3 # Copyright (c) 2006 Johannes E. Schindelin
7 # This script makes it easy to fix up commits in the middle of a series,
8 # and rearrange commits.
10 # The original idea comes from Eric W. Biederman, in
11 # http://article.gmane.org/gmane.comp.version-control.git/22407
15 git-rebase [-i] [options] [--] <upstream> [<branch>]
16 git-rebase [-i] (--continue | --abort | --skip)
19 v,verbose display a diffstat of what changed upstream
20 onto= rebase onto given branch instead of upstream
21 p,preserve-merges try to recreate merges instead of ignoring them
22 s,strategy= use the given merge strategy
23 m,merge always used (no-op)
24 i,interactive always used (no-op)
26 continue continue rebasing process
27 abort abort rebasing process and restore original branch
28 skip skip current patch and continue rebasing process
29 no-verify override pre-rebase hook from stopping the operation
30 root rebase all reachable commmits up to the root(s)
31 autosquash move commits that begin with squash!/fixup! under -i
37 DOTEST
="$GIT_DIR/rebase-merge"
39 # The file containing rebase commands, comments, and empty lines.
40 # This file is created by "git rebase -i" then edited by the user. As
41 # the lines are processed, they are removed from the front of this
42 # file and written to the tail of $DONE.
43 TODO
="$DOTEST"/git-rebase-todo
45 # The rebase command lines that have already been processed. A line
46 # is moved here when it is first handled, before any associated user
50 # The commit message that is planned to be used for any changes that
51 # need to be committed following a user interaction.
54 # The file into which is accumulated the suggested commit message for
55 # squash/fixup commands. When the first of a series of squash/fixups
56 # is seen, the file is created and the commit message from the
57 # previous commit and from the first squash/fixup commit are written
58 # to it. The commit message for each subsequent squash/fixup commit
59 # is appended to the file as it is processed.
61 # The first line of the file is of the form
62 # # This is a combination of $COUNT commits.
63 # where $COUNT is the number of commits whose messages have been
64 # written to the file so far (including the initial "pick" commit).
65 # Each time that a commit message is processed, this line is read and
66 # updated. It is deleted just before the combined commit is made.
67 SQUASH_MSG
="$DOTEST"/message-squash
69 # If the current series of squash/fixups has not yet included a squash
70 # command, then this file exists and holds the commit message of the
71 # original "pick" commit. (If the series ends without a "squash"
72 # command, then this can be used as the commit message of the combined
73 # commit without opening the editor.)
74 FIXUP_MSG
="$DOTEST"/message-fixup
76 # $REWRITTEN is the name of a directory containing files for each
77 # commit that is reachable by at least one merge base of $HEAD and
78 # $UPSTREAM. They are not necessarily rewritten, but their children
79 # might be. This ensures that commits on merged, but otherwise
80 # unrelated side branches are left alone. (Think "X" in the man page's
82 REWRITTEN
="$DOTEST"/rewritten
84 DROPPED
="$DOTEST"/dropped
86 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
87 # GIT_AUTHOR_DATE that will be used for the commit that is currently
89 AUTHOR_SCRIPT
="$DOTEST"/author-script
91 # When an "edit" rebase command is being processed, the SHA1 of the
92 # commit to be edited is recorded in this file. When "git rebase
93 # --continue" is executed, if there are any staged changes then they
94 # will be amended to the HEAD commit, but only provided the HEAD
95 # commit is still the commit to be edited. When any other rebase
96 # command is processed, this file is deleted.
103 OK_TO_SKIP_PRE_REBASE
=
107 GIT_CHERRY_PICK_HELP
=" After resolving the conflicts,
108 mark the corrected paths with 'git add <paths>', and
109 run 'git rebase --continue'"
110 export GIT_CHERRY_PICK_HELP
121 test $status != 0 && printf "%s\n" "$output"
130 # Output the commit message for the specified commit.
132 git cat-file commit
"$1" |
sed "1,/^$/d"
135 run_pre_rebase_hook
() {
136 if test -z "$OK_TO_SKIP_PRE_REBASE" &&
137 test -x "$GIT_DIR/hooks/pre-rebase"
139 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
{
140 echo >&2 "The pre-rebase hook refused to rebase."
146 require_clean_work_tree
() {
147 # test if working tree is dirty
148 git rev-parse
--verify HEAD
> /dev
/null
&&
149 git update-index
--ignore-submodules --refresh &&
150 git diff-files
--quiet --ignore-submodules &&
151 git diff-index
--cached --quiet HEAD
--ignore-submodules -- ||
152 die
"Working tree is dirty"
155 ORIG_REFLOG_ACTION
="$GIT_REFLOG_ACTION"
157 comment_for_reflog
() {
158 case "$ORIG_REFLOG_ACTION" in
160 GIT_REFLOG_ACTION
="rebase -i ($1)"
161 export GIT_REFLOG_ACTION
166 peek_next_command
() {
167 sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO"
170 # expects the original commit name(s) in "$REWRITTEN"/original
171 # records the current HEAD as the rewritten commit
173 test ! -d "$REWRITTEN" && return
174 rewritten
=$
(git rev-parse
--verify HEAD
) &&
175 for original
in $
(cat "$REWRITTEN"/original
)
177 original
=$
(git rev-parse
--verify "$original") &&
178 echo $rewritten > "$REWRITTEN"/$original ||
break
180 case "$(peek_next_command)" in
181 squash|s
) ;; # do nothing
182 *) rm "$REWRITTEN"/original
;;
184 die
"Could not store information about rewritten commit"
187 # if the given commit name ends in an apostrophe, returns the rewritten commit
191 rewritten
=$
(git rev-parse
--verify ${1%\'}) || die
192 while test -f "$REWRITTEN"/$rewritten -o -f "$DROPPED"/$rewritten
194 test -f "$REWRITTEN"/$rewritten &&
195 new_rewritten
=$
(cat "$REWRITTEN"/$rewritten) ||
196 new_rewritten
=$
(cat "$DROPPED"/$rewritten) ||
break
197 test $rewritten = $new_rewritten && break
198 rewritten
=$new_rewritten
203 git rev-parse
--verify $1 || die
209 mark_action_done
() {
210 sed -e 1q
< "$TODO" >> "$DONE"
211 sed -e 1d
< "$TODO" >> "$TODO".new
212 mv -f "$TODO".new
"$TODO"
213 count
=$
(sane_grep
-c '^[^#]' < "$DONE")
214 total
=$
(($count+$
(sane_grep
-c '^[^#]' < "$TODO")))
215 if test "$last_count" != "$count"
218 printf "Rebasing (%d/%d)\r" $count $total
219 test -z "$VERBOSE" ||
echo
224 sha1_and_parents
="$(git rev-list --parents -1 "$1")"
225 case "$sha1_and_parents" in
227 git
diff --cc $sha1_and_parents
230 git diff-tree
-p "$1^!"
235 esac > "$DOTEST"/patch
237 commit_message
"$1" > "$MSG"
238 test -f "$AUTHOR_SCRIPT" ||
239 get_author_ident_from_commit
"$1" > "$AUTHOR_SCRIPT"
243 test -d "$REWRITTEN" && git rev-parse
"$1" >> "$REWRITTEN"/original
255 sane_grep
'^[^#]' "$1" >/dev
/null
258 # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
259 # GIT_AUTHOR_DATE exported from the current environment.
262 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
269 case "$1" in -n) sha1
=$2; no_ff
=t
;; *) sha1
=$1 ;; esac
270 test -d "$REWRITTEN" && echo "$sha1" >> "$REWRITTEN"/original
271 output git rev-parse
--verify $sha1 || die
"Invalid commit name: $sha1"
272 test -d "$REWRITTEN" &&
273 pick_one_preserving_merges
"$@" && return
274 if test -n "$REBASE_ROOT"
276 output git cherry-pick
"$@"
279 parent_sha1
=$
(git rev-parse
--verify $sha1^
) ||
280 die
"Could not get the parent of $sha1"
281 current_sha1
=$
(git rev-parse
--verify HEAD
)
282 if test -z "$no_ff" && test "$current_sha1" = "$parent_sha1"
284 output git
reset --hard $sha1
285 output warn Fast-forward to $
(git rev-parse
--short $sha1)
287 output git cherry-pick
"$@"
293 test "$1" = parents
&& shift
295 while test "original" != "$1"
297 parents
="$parents $(parse_commit $1)"
301 test "original" != "$1" &&
302 die
"Could not determine original merge commit from $cmd"
304 sha1
=$2; shift; shift
306 # the command was "merge parents ...", so "parents" was recorded
307 # TODO: detect non-fast-forwards properly
308 ORIGINAL_HEAD
=$
(git rev-parse HEAD
) &&
309 git merge
$parents &&
310 if test $ORIGINAL_HEAD = "$(git rev-parse HEAD^)"
312 git commit
--amend -m "$*" &&
313 echo "$sha1" > "$REWRITTEN"/original
&&
316 die_with_patch
$sha1 "Could not redo merge $sha1 with parents $parents"
319 pick_one_preserving_merges
() {
330 sha1
=$
(git rev-parse
$sha1)
331 echo $sha1 > "$REWRITTEN"/original
333 if test -f "$DOTEST"/current-commit
335 if test "$fast_forward" = t
337 cat "$DOTEST"/current-commit |
while read current_commit
339 git rev-parse HEAD
> "$REWRITTEN"/$current_commit
341 rm "$DOTEST"/current-commit ||
342 die
"Cannot write current commit's replacement sha1"
346 echo $sha1 >> "$DOTEST"/current-commit
348 # rewrite parents; if none were rewritten, we can fast-forward.
350 pend
=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
351 if test "$pend" = " "
355 while [ "$pend" != "" ]
357 p
=$
(expr "$pend" : ' \([^ ]*\)')
360 if test -f "$REWRITTEN"/$p
362 new_p
=$
(cat "$REWRITTEN"/$p)
364 # If the todo reordered commits, and our parent is marked for
365 # rewriting, but hasn't been gotten to yet, assume the user meant to
366 # drop it on top of the current HEAD
369 new_p
=$
(git rev-parse HEAD
)
372 test $p != $new_p && fast_forward
=f
373 case "$new_parents" in
375 ;; # do nothing; that parent is already there
377 new_parents
="$new_parents $new_p"
381 if test -f "$DROPPED"/$p
384 replacement
="$(cat "$DROPPED"/$p)"
385 test -z "$replacement" && replacement
=root
386 pend
=" $replacement$pend"
388 new_parents
="$new_parents $p"
392 case $fast_forward in
394 output warn
"Fast-forward to $sha1"
395 output git
reset --hard $sha1 ||
396 die
"Cannot fast-forward to $sha1"
399 first_parent
=$
(expr "$new_parents" : ' \([^ ]*\)')
403 # detach HEAD to current parent
404 output git checkout
$first_parent 2> /dev
/null ||
405 die
"Cannot move HEAD to $first_parent"
408 case "$new_parents" in
410 test "a$1" = a-n
&& die
"Refusing to squash a merge: $sha1"
413 author_script
=$
(get_author_ident_from_commit
$sha1)
414 eval "$author_script"
415 msg
="$(commit_message $sha1)"
416 # No point in merging the first parent, that's HEAD
417 new_parents
=${new_parents# $first_parent}
418 if ! do_with_author output \
419 git merge
$STRATEGY -m "$msg" $new_parents
421 printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
422 die_with_patch
$sha1 "Error redoing merge $sha1"
426 output git cherry-pick
"$@" ||
427 die_with_patch
$sha1 "Could not pick $sha1"
436 *1[0-9]|
*[04-9]) echo "$1"th
;;
443 update_squash_messages
() {
444 if test -f "$SQUASH_MSG"; then
445 mv "$SQUASH_MSG" "$SQUASH_MSG".bak ||
exit
447 -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
448 -e "q" < "$SQUASH_MSG".bak
)+1))
450 echo "# This is a combination of $COUNT commits."
451 sed -e 1d
-e '2,/^./{
453 }' <"$SQUASH_MSG".bak
456 commit_message HEAD
> "$FIXUP_MSG" || die
"Cannot write $FIXUP_MSG"
459 echo "# This is a combination of 2 commits."
460 echo "# The first commit's message is:"
469 echo "# This is the $(nth_string $COUNT) commit message:"
475 echo "# The $(nth_string $COUNT) commit message will be skipped:"
477 commit_message
$2 |
sed -e 's/^/# /'
482 # A squash/fixup has failed. Prepare the long version of the squash
483 # commit message, then die_with_patch. This code path requires the
484 # user to edit the combined commit message for all commits that have
485 # been squashed/fixedup so far. So also erase the old squash
486 # messages, effectively causing the combined commit to be used as the
487 # new basis for any further squash/fixups. Args: sha1 rest
488 die_failed_squash
() {
489 mv "$SQUASH_MSG" "$MSG" ||
exit
491 cp "$MSG" "$GIT_DIR"/MERGE_MSG ||
exit
493 warn
"Could not apply $1... $2"
498 rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" ||
exit
499 read command sha1 rest
< "$TODO"
505 comment_for_reflog pick
508 pick_one
$sha1 && add_rewritten ||
509 die_with_patch
$sha1 "Could not apply $sha1... $rest"
512 comment_for_reflog reword
516 die_with_patch
$sha1 "Could not apply $sha1... $rest"
520 comment_for_reflog edit
524 die_with_patch
$sha1 "Could not apply $sha1... $rest"
526 git rev-parse
--verify HEAD
> "$AMEND"
527 warn
"Stopped at $sha1... $rest"
528 warn
"You can amend the commit now, with"
530 warn
" git commit --amend"
532 warn
"Once you are satisfied with your changes, run"
534 warn
" git rebase --continue"
547 comment_for_reflog
$squash_style
549 test -f "$DONE" && has_action
"$DONE" ||
550 die
"Cannot '$squash_style' without a previous commit"
553 update_squash_messages
$squash_style $sha1
554 author_script
=$
(get_author_ident_from_commit HEAD
)
555 echo "$author_script" > "$AUTHOR_SCRIPT"
556 eval "$author_script"
557 output git
reset --soft HEAD^
558 pick_one
-n $sha1 || die_failed_squash
$sha1 "$rest"
559 case "$(peek_next_command)" in
561 # This is an intermediate commit; its message will only be
562 # used in case of trouble. So use the long version:
563 do_with_author output git commit
--no-verify -F "$SQUASH_MSG" &&
565 die_failed_squash
$sha1 "$rest"
568 # This is the final command of this squash/fixup group
569 if test -f "$FIXUP_MSG"
571 do_with_author git commit
--no-verify -F "$FIXUP_MSG" &&
573 die_failed_squash
$sha1 "$rest"
575 cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG ||
exit
576 rm -f "$GIT_DIR"/MERGE_MSG
577 do_with_author git commit
--no-verify -e &&
579 die_failed_squash
$sha1 "$rest"
581 rm -f "$SQUASH_MSG" "$FIXUP_MSG"
586 comment_for_reflog goto
588 output git
reset --hard $
(parse_commit
$sha1) ||
589 die
"Could not reset to $sha1"
592 comment_for_reflog merge
594 # this already dies with patch on error
595 output merge_one
$sha1 $rest ||
# $sha1 is not the real sha1...
599 warn
"Unknown command: $command $sha1 $rest"
600 if git rev-parse
--verify -q "$sha1" >/dev
/null
602 die_with_patch
$sha1 "Please fix this in the file $TODO."
604 die
"Please fix this in the file $TODO."
608 test -s "$TODO" && return
610 comment_for_reflog finish
&&
611 HEADNAME
=$
(cat "$DOTEST"/head-name
) &&
612 OLDHEAD
=$
(cat "$DOTEST"/head) &&
613 SHORTONTO
=$
(git rev-parse
--short $
(cat "$DOTEST"/onto
)) &&
614 NEWHEAD
=$
(git rev-parse HEAD
) &&
617 message
="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
618 git update-ref
-m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
619 git symbolic-ref HEAD
$HEADNAME
622 test ! -f "$DOTEST"/verbose ||
623 git diff-tree
--stat $
(cat "$DOTEST"/head)..HEAD
627 warn
"Successfully rebased and updated $HEADNAME."
639 # skip picking commits whose parents are unchanged
640 skip_unnecessary_picks
() {
642 while read command sha1 rest
644 # fd=3 means we skip the command
645 case "$fd,$command,$(git rev-parse --verify --quiet $sha1^)" in
646 3,pick
,"$ONTO"*|
3,p
,"$ONTO"*)
647 # pick a commit whose parent is current $ONTO -> skip
657 echo "$command${sha1:+ }$sha1${rest:+ }$rest" >&$fd
658 done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
659 mv -f "$TODO".new
"$TODO" ||
660 die
"Could not skip unnecessary pick commands"
663 # check if no other options are set
665 test $# -eq 2 -a "$2" = '--' &&
667 test -z "$PRESERVE_MERGES" &&
668 test -z "$STRATEGY" &&
672 get_saved_options
() {
673 test -d "$REWRITTEN" && PRESERVE_MERGES
=t
674 test -f "$DOTEST"/strategy
&& STRATEGY
="$(cat "$DOTEST"/strategy)"
675 test -f "$DOTEST"/verbose
&& VERBOSE
=t
676 test -f "$DOTEST"/rebase-root
&& REBASE_ROOT
=t
679 # Rearrange the todo list that has both "pick sha1 msg" and
680 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
681 # comes immediately after the former, and change "pick" to
683 rearrange_squash
() {
684 sed -n -e 's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p' \
685 -e 's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p' \
687 test -s "$1.sq" ||
return
690 while read pick sha1 message
693 *" $sha1 "*) continue ;;
695 echo "$pick $sha1 $message"
696 while read squash action msg
700 echo "$action $squash $action! $msg"
705 done >"$1.rearranged" <"$1"
706 cat "$1.rearranged" >"$1"
707 rm -f "$1.sq" "$1.rearranged"
715 if left
=${1%...*} right
=${1#*...} &&
716 onto
=$
(git merge-base
--all ${left:-HEAD} ${right:-HEAD})
726 git rev-parse
--verify "$1^0"
729 prepare_preserve_merges
() {
730 # $REWRITTEN contains files for each commit that is
731 # reachable by at least one merge base of $HEAD and
732 # $UPSTREAM. They are not necessarily rewritten, but
733 # their children might be.
734 # This ensures that commits on merged, but otherwise
735 # unrelated side branches are left alone. (Think "X"
736 # in the man page's example.)
737 if test -z "$REBASE_ROOT"
739 mkdir
"$REWRITTEN" &&
740 for c
in $
(git merge-base
--all $HEAD $UPSTREAM)
742 echo $ONTO > "$REWRITTEN"/$c ||
743 die
"Could not init rewritten commits"
746 mkdir
"$REWRITTEN" &&
747 echo $ONTO > "$REWRITTEN"/root ||
748 die
"Could not init rewritten commits"
750 # No cherry-pick because our first pass is to determine
751 # parents to rewrite and skipping dropped commits would
752 # prematurely end our probe
754 first_after_upstream
="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
757 handle_dropped_commits
() {
758 # Watch for commits that been dropped by --cherry-pick
760 # Save all non-cherry-picked changes
761 git rev-list
$REVISIONS --left-right --cherry-pick | \
762 sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
763 # Now all commits and note which ones are missing in
764 # not-cherry-picks and hence being dropped
765 git rev-list
$REVISIONS |
768 if test -f "$REWRITTEN"/$rev -a "$(grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
770 # Use -f2 because if rev-list is telling us this commit is
771 # not worthwhile, we don't want to track its multiple heads,
772 # just the history of its first-parent for others that will
773 # be rebasing on top of it
774 git rev-list
--parents -1 $rev | cut
-d' ' -s -f2 > "$DROPPED"/$rev
775 short
=$
(git rev-list
-1 --abbrev-commit --abbrev=7 $rev)
776 grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
782 generate_script_help
() {
783 cat >> "$TODO" << EOF
785 # Rebase $SHORTREVISIONS onto $SHORTONTO
788 # p, pick = use commit
789 # r, reword = use commit, but edit the commit message
790 # e, edit = use commit, but stop for amending
791 # s, squash = use commit, but meld into previous commit
792 # f, fixup = like "squash", but discard this commit's log message
793 # g, goto = reset the current state to the given commit
794 # m, merge parents <parents> original <original merge commit>
795 # = redo the given merge commit
797 # If you remove a line here THAT COMMIT WILL BE LOST.
798 # However, if you remove everything, the rebase will be aborted.
805 test -z "$(git rev-list $MERGES_OPTION --cherry-pick --left-right \
806 $REVISIONS | grep '^>')" && {
812 git rev-list
$MERGES_OPTION --pretty=oneline
--abbrev-commit \
813 --abbrev=7 --reverse --left-right --topo-order \
815 sed -n "s/^>//p" |
while read shortsha1 rest
817 if test t
!= "$PRESERVE_MERGES"
819 echo "pick $shortsha1 $rest"
821 sha1
=$
(git rev-parse
$shortsha1)
822 if test -z "$REBASE_ROOT"
825 for p
in $
(git rev-list
--parents -1 $sha1 | cut
-d' ' -s -f2-)
827 if test -f "$REWRITTEN"/$p -a \
( $p != $UPSTREAM -o $sha1 = $first_after_upstream \
)
835 if test f
= "$preserve"
837 touch "$REWRITTEN"/$sha1
838 echo "pick $shortsha1 $rest"
850 OK_TO_SKIP_PRE_REBASE
=yes
855 is_standalone
"$@" || usage
857 comment_for_reflog
continue
859 test -d "$DOTEST" || die
"No interactive rebase running"
862 git rev-parse
--verify HEAD
>/dev
/null ||
863 die
"Cannot read HEAD"
864 git update-index
--ignore-submodules --refresh &&
865 git diff-files
--quiet --ignore-submodules ||
866 die
"Working tree is dirty"
868 # do we have anything to commit?
869 if git diff-index
--cached --quiet --ignore-submodules HEAD
--
872 test ! -f "$REWRITTEN"/original || add_rewritten
874 .
"$AUTHOR_SCRIPT" ||
875 die
"Cannot find the author identity"
879 amend
=$
(git rev-parse
--verify HEAD
)
880 test "$amend" = $
(cat "$AMEND") ||
882 You have uncommitted changes in your working tree. Please, commit them
883 first and then run 'git rebase --continue' again."
884 git
reset --soft HEAD^ ||
885 die
"Cannot rewind the HEAD"
887 do_with_author git commit
--no-verify -F "$MSG" -e &&
889 test -n "$amend" && git
reset --soft $amend
890 die
"Could not commit staged changes."
894 require_clean_work_tree
898 is_standalone
"$@" || usage
900 comment_for_reflog abort
903 test -d "$DOTEST" || die
"No interactive rebase running"
905 HEADNAME
=$
(cat "$DOTEST"/head-name
)
906 HEAD
=$
(cat "$DOTEST"/head)
909 git symbolic-ref HEAD
$HEADNAME
912 output git
reset --hard $HEAD &&
917 is_standalone
"$@" || usage
919 comment_for_reflog skip
922 test -d "$DOTEST" || die
"No interactive rebase running"
924 test -d "$REWRITTEN" && {
925 # skip last to-be-rewritten commit
926 original_count
=$
(wc -l < "$REWRITTEN"/original
)
927 test $original_count -gt 0 &&
928 head -n $
(($original_count-1)) < "$REWRITTEN"/original \
929 > "$REWRITTEN"/original.new
&&
930 mv "$REWRITTEN"/original.new
"$REWRITTEN"/original
932 output git
reset --hard && do_rest
937 STRATEGY
="-s "$
(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
946 # we use merge anyway
965 ONTO
=$
(parse_onto
"$1") ||
966 die
"Does not point to a valid commit: $1"
970 test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
971 test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
973 die
"Interactive rebase already started"
975 git var GIT_COMMITTER_IDENT
>/dev
/null ||
976 die
"You need to set your committer info first"
978 if test -z "$REBASE_ROOT"
981 UPSTREAM
=$
(git rev-parse
--verify "$1") ||
983 test -z "$ONTO" && ONTO
=$UPSTREAM
989 die
"You must specify --onto when using --root"
992 run_pre_rebase_hook
"$UPSTREAM_ARG" "$@"
994 comment_for_reflog start
996 require_clean_work_tree
1000 output git show-ref
--verify --quiet "refs/heads/$1" ||
1001 die
"Invalid branchname: $1"
1002 output git checkout
"$1" ||
1003 die
"Could not checkout $1"
1006 HEAD
=$
(git rev-parse
--verify HEAD
) || die
"No HEAD?"
1007 mkdir
"$DOTEST" || die
"Could not create temporary $DOTEST"
1009 : > "$DOTEST"/interactive || die
"Could not mark as interactive"
1010 git symbolic-ref HEAD
> "$DOTEST"/head-name
2> /dev
/null ||
1011 echo "detached HEAD" > "$DOTEST"/head-name
1013 echo $HEAD > "$DOTEST"/head
1014 test -z "$REBASE_ROOT" ||
: >"$DOTEST"/rebase-root
1015 echo $ONTO > "$DOTEST"/onto
1016 test -z "$STRATEGY" ||
echo "$STRATEGY" > "$DOTEST"/strategy
1017 test t
= "$VERBOSE" && : > "$DOTEST"/verbose
1019 SHORTHEAD
=$
(git rev-parse
--short $HEAD)
1020 SHORTONTO
=$
(git rev-parse
--short $ONTO)
1021 SHORTUPSTREAM
=$
(git rev-parse
--short $UPSTREAM)
1022 REVISIONS
=$UPSTREAM...
$HEAD
1023 SHORTREVISIONS
=$SHORTUPSTREAM..
$SHORTHEAD
1025 MERGES_OPTION
="--no-merges --cherry-pick"
1026 test t
= "$PRESERVE_MERGES" && prepare_preserve_merges
1028 generate_script
> "$TODO"
1029 test -n "$AUTOSQUASH" && rearrange_squash
"$TODO"
1032 test t
= "$PRESERVE_MERGES" && handle_dropped_commits
1034 has_action
"$TODO" ||
1035 die_abort
"Nothing to do"
1037 cp "$TODO" "$TODO".backup
1038 git_editor
"$TODO" ||
1039 die_abort
"Could not execute editor"
1041 has_action
"$TODO" ||
1042 die_abort
"Nothing to do"
1044 test -d "$REWRITTEN" || skip_unnecessary_picks
1046 git update-ref ORIG_HEAD
$HEAD
1047 output git checkout
$ONTO && do_rest