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
13 # The file containing rebase commands, comments, and empty lines.
14 # This file is created by "git rebase -i" then edited by the user. As
15 # the lines are processed, they are removed from the front of this
16 # file and written to the tail of $done.
17 todo="$state_dir"/git-rebase-todo
19 # The rebase command lines that have already been processed. A line
20 # is moved here when it is first handled, before any associated user
22 done="$state_dir"/done
24 # The commit message that is planned to be used for any changes that
25 # need to be committed following a user interaction.
26 msg="$state_dir"/message
28 # The file into which is accumulated the suggested commit message for
29 # squash/fixup commands. When the first of a series of squash/fixups
30 # is seen, the file is created and the commit message from the
31 # previous commit and from the first squash/fixup commit are written
32 # to it. The commit message for each subsequent squash/fixup commit
33 # is appended to the file as it is processed.
35 # The first line of the file is of the form
36 # # This is a combination of $count commits.
37 # where $count is the number of commits whose messages have been
38 # written to the file so far (including the initial "pick" commit).
39 # Each time that a commit message is processed, this line is read and
40 # updated. It is deleted just before the combined commit is made.
41 squash_msg="$state_dir"/message-squash
43 # If the current series of squash/fixups has not yet included a squash
44 # command, then this file exists and holds the commit message of the
45 # original "pick" commit. (If the series ends without a "squash"
46 # command, then this can be used as the commit message of the combined
47 # commit without opening the editor.)
48 fixup_msg="$state_dir"/message-fixup
50 # $rewritten is the name of a directory containing files for each
51 # commit that is reachable by at least one merge base of $head and
52 # $upstream. They are not necessarily rewritten, but their children
53 # might be. This ensures that commits on merged, but otherwise
54 # unrelated side branches are left alone. (Think "X" in the man page's
56 rewritten="$state_dir"/rewritten
58 dropped="$state_dir"/dropped
61 msgnum="$state_dir"/msgnum
63 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
64 # GIT_AUTHOR_DATE that will be used for the commit that is currently
66 author_script="$state_dir"/author-script
68 # When an "edit" rebase command is being processed, the SHA1 of the
69 # commit to be edited is recorded in this file. When "git rebase
70 # --continue" is executed, if there are any staged changes then they
71 # will be amended to the HEAD commit, but only provided the HEAD
72 # commit is still the commit to be edited. When any other rebase
73 # command is processed, this file is deleted.
74 amend="$state_dir"/amend
76 # For the post-rewrite hook, we make a list of rewritten commits and
77 # their new sha1s. The rewritten-pending list keeps the sha1s of
78 # commits that have been processed, but not committed yet,
79 # e.g. because they are waiting for a 'squash' command.
80 rewritten_list="$state_dir"/rewritten-list
81 rewritten_pending="$state_dir"/rewritten-pending
84 if test -n "$do_merge"
86 strategy_args=${strategy:+--strategy=$strategy}
88 for strategy_opt in '"$strategy_opts"'
90 strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
95 GIT_CHERRY_PICK_HELP="$resolvemsg"
96 export GIT_CHERRY_PICK_HELP
98 comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
102 printf '%s\n' "$*" >&2
105 # Output the commit message for the specified commit.
107 git cat-file commit "$1" | sed "1,/^$/d"
110 orig_reflog_action="$GIT_REFLOG_ACTION"
112 comment_for_reflog () {
113 case "$orig_reflog_action" in
115 GIT_REFLOG_ACTION="rebase -i ($1)"
116 export GIT_REFLOG_ACTION
122 mark_action_done () {
123 sed -e 1q < "$todo" >> "$done"
124 sed -e 1d < "$todo" >> "$todo".new
125 mv -f "$todo".new "$todo"
126 new_count=$(git stripspace --strip-comments <"$done" | wc -l)
127 echo $new_count >"$msgnum"
128 total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
130 if test "$last_count" != "$new_count"
132 last_count=$new_count
133 printf "Rebasing (%d/%d)\r" $new_count $total
134 test -z "$verbose" || echo
138 append_todo_help () {
139 git stripspace --comment-lines >>"$todo" <<\EOF
143 r, reword = use commit, but edit the commit message
144 e, edit = use commit, but stop for amending
145 s, squash = use commit, but meld into previous commit
146 f, fixup = like "squash", but discard this commit's log message
147 x, exec = run command (the rest of the line) using shell
149 These lines can be re-ordered; they are executed from top to bottom.
151 If you remove a line here THAT COMMIT WILL BE LOST.
156 sha1_and_parents="$(git rev-list --parents -1 "$1")"
157 case "$sha1_and_parents" in
159 git diff --cc $sha1_and_parents
162 git diff-tree -p "$1^!"
167 esac > "$state_dir"/patch
169 commit_message "$1" > "$msg"
170 test -f "$author_script" ||
171 get_author_ident_from_commit "$1" > "$author_script"
175 echo "$1" > "$state_dir"/stopped-sha
182 echo "$1" > "$state_dir"/stopped-sha
184 git rev-parse --verify HEAD > "$amend"
185 warn "You can amend the commit now, with"
187 warn " git commit --amend"
189 warn "Once you are satisfied with your changes, run"
191 warn " git rebase --continue"
202 test -n "$(git stripspace --strip-comments <"$1")"
206 tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null ||
207 die "$1: not a commit that can be picked")
208 ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null ||
209 ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904)
210 test "$tree" = "$ptree"
215 git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
218 # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
219 # GIT_AUTHOR_DATE exported from the current environment.
222 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
227 git_sequence_editor () {
228 if test -z "$GIT_SEQUENCE_EDITOR"
230 GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"
231 if [ -z "$GIT_SEQUENCE_EDITOR" ]
233 GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?
237 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
243 case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
244 case "$force_rebase" in '') ;; ?*) ff= ;; esac
245 output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
247 if is_empty_commit "$sha1"
249 empty_args="--allow-empty"
252 test -d "$rewritten" &&
253 pick_one_preserving_merges "$@" && return
254 output eval git cherry-pick "$strategy_args" $empty_args $ff "$@"
257 pick_one_preserving_merges () {
268 sha1=$(git rev-parse $sha1)
270 if test -f "$state_dir"/current-commit
272 if test "$fast_forward" = t
274 while read current_commit
276 git rev-parse HEAD > "$rewritten"/$current_commit
277 done <"$state_dir"/current-commit
278 rm "$state_dir"/current-commit ||
279 die "Cannot write current commit's replacement sha1"
283 echo $sha1 >> "$state_dir"/current-commit
285 # rewrite parents; if none were rewritten, we can fast-forward.
287 pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
288 if test "$pend" = " "
292 while [ "$pend" != "" ]
294 p=$(expr "$pend" : ' \([^ ]*\)')
297 if test -f "$rewritten"/$p
299 new_p=$(cat "$rewritten"/$p)
301 # If the todo reordered commits, and our parent is marked for
302 # rewriting, but hasn't been gotten to yet, assume the user meant to
303 # drop it on top of the current HEAD
306 new_p=$(git rev-parse HEAD)
309 test $p != $new_p && fast_forward=f
310 case "$new_parents" in
312 ;; # do nothing; that parent is already there
314 new_parents="$new_parents $new_p"
318 if test -f "$dropped"/$p
321 replacement="$(cat "$dropped"/$p)"
322 test -z "$replacement" && replacement=root
323 pend=" $replacement$pend"
325 new_parents="$new_parents $p"
329 case $fast_forward in
331 output warn "Fast-forward to $sha1"
332 output git reset --hard $sha1 ||
333 die "Cannot fast-forward to $sha1"
336 first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
340 # detach HEAD to current parent
341 output git checkout $first_parent 2> /dev/null ||
342 die "Cannot move HEAD to $first_parent"
345 case "$new_parents" in
347 test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
350 author_script_content=$(get_author_ident_from_commit $sha1)
351 eval "$author_script_content"
352 msg_content="$(commit_message $sha1)"
353 # No point in merging the first parent, that's HEAD
354 new_parents=${new_parents# $first_parent}
355 if ! do_with_author output eval \
356 'git merge --no-ff $strategy_args -m "$msg_content" $new_parents'
358 printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
359 die_with_patch $sha1 "Error redoing merge $sha1"
361 echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
364 output eval git cherry-pick "$strategy_args" "$@" ||
365 die_with_patch $sha1 "Could not pick $sha1"
374 *1[0-9]|*[04-9]) echo "$1"th;;
381 update_squash_messages () {
382 if test -f "$squash_msg"; then
383 mv "$squash_msg" "$squash_msg".bak || exit
385 -e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
386 -e "q" < "$squash_msg".bak)+1))
388 printf '%s\n' "$comment_char This is a combination of $count commits."
389 sed -e 1d -e '2,/^./{
391 }' <"$squash_msg".bak
394 commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
397 printf '%s\n' "$comment_char This is a combination of 2 commits."
398 printf '%s\n' "$comment_char The first commit's message is:"
407 printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
413 printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
415 # Change the space after the comment character to TAB:
416 commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
421 peek_next_command () {
422 git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
425 # A squash/fixup has failed. Prepare the long version of the squash
426 # commit message, then die_with_patch. This code path requires the
427 # user to edit the combined commit message for all commits that have
428 # been squashed/fixedup so far. So also erase the old squash
429 # messages, effectively causing the combined commit to be used as the
430 # new basis for any further squash/fixups. Args: sha1 rest
431 die_failed_squash() {
432 mv "$squash_msg" "$msg" || exit
434 cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
436 warn "Could not apply $1... $2"
440 flush_rewritten_pending() {
441 test -s "$rewritten_pending" || return
442 newsha1="$(git rev-parse HEAD^0)"
443 sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
444 rm -f "$rewritten_pending"
447 record_in_rewritten() {
448 oldsha1="$(git rev-parse $1)"
449 echo "$oldsha1" >> "$rewritten_pending"
451 case "$(peek_next_command)" in
455 flush_rewritten_pending
461 if test "$(git rev-parse HEAD)" = "$squash_onto"
463 # Set the correct commit message and author info on the
464 # sentinel root before cherry-picking the original changes
465 # without committing (-n). Finally, update the sentinel again
466 # to include these changes. If the cherry-pick results in a
467 # conflict, this means our behaviour is similar to a standard
468 # failed cherry-pick during rebase, with a dirty index to
469 # resolve before manually running git commit --amend then git
471 git commit --allow-empty --allow-empty-message --amend \
472 --no-post-rewrite -n -q -C $1 &&
474 git commit --allow-empty --allow-empty-message \
475 --amend --no-post-rewrite -n -q -C $1 ||
476 die_with_patch $1 "Could not apply $1... $2"
479 die_with_patch $1 "Could not apply $1... $2"
484 rm -f "$msg" "$author_script" "$amend" || exit
485 read -r command sha1 rest < "$todo"
487 "$comment_char"*|''|noop)
491 comment_for_reflog pick
494 do_pick $sha1 "$rest"
495 record_in_rewritten $sha1
498 comment_for_reflog reword
501 do_pick $sha1 "$rest"
502 git commit --amend --no-post-rewrite || {
503 warn "Could not amend commit after successfully picking $sha1... $rest"
504 warn "This is most likely due to an empty commit message, or the pre-commit hook"
505 warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
506 warn "you are able to reword the commit."
507 exit_with_patch $sha1 1
509 record_in_rewritten $sha1
512 comment_for_reflog edit
515 do_pick $sha1 "$rest"
516 warn "Stopped at $sha1... $rest"
517 exit_with_patch $sha1 0
528 comment_for_reflog $squash_style
530 test -f "$done" && has_action "$done" ||
531 die "Cannot '$squash_style' without a previous commit"
534 update_squash_messages $squash_style $sha1
535 author_script_content=$(get_author_ident_from_commit HEAD)
536 echo "$author_script_content" > "$author_script"
537 eval "$author_script_content"
538 if ! pick_one -n $sha1
540 git rev-parse --verify HEAD >"$amend"
541 die_failed_squash $sha1 "$rest"
543 case "$(peek_next_command)" in
545 # This is an intermediate commit; its message will only be
546 # used in case of trouble. So use the long version:
547 do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
548 die_failed_squash $sha1 "$rest"
551 # This is the final command of this squash/fixup group
552 if test -f "$fixup_msg"
554 do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
555 die_failed_squash $sha1 "$rest"
557 cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
558 rm -f "$GIT_DIR"/MERGE_MSG
559 do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
560 die_failed_squash $sha1 "$rest"
562 rm -f "$squash_msg" "$fixup_msg"
565 record_in_rewritten $sha1
568 read -r command rest < "$todo"
570 printf 'Executing: %s\n' "$rest"
571 # "exec" command doesn't take a sha1 in the todo-list.
572 # => can't just use $sha1 here.
573 git rev-parse --verify HEAD > "$state_dir"/stopped-sha
574 ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
576 # Run in subshell because require_clean_work_tree can die.
578 (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
579 if test "$status" -ne 0
581 warn "Execution failed: $rest"
583 warn "and made changes to the index and/or the working tree"
585 warn "You can fix the problem, and then run"
587 warn " git rebase --continue"
589 if test $status -eq 127 # command not found
594 elif test "$dirty" = t
596 warn "Execution succeeded: $rest"
597 warn "but left changes to the index and/or the working tree"
598 warn "Commit or stash your changes, and then run"
600 warn " git rebase --continue"
606 warn "Unknown command: $command $sha1 $rest"
607 fixtodo="Please fix this using 'git rebase --edit-todo'."
608 if git rev-parse --verify -q "$sha1" >/dev/null
610 die_with_patch $sha1 "$fixtodo"
616 test -s "$todo" && return
618 comment_for_reflog finish &&
619 newhead=$(git rev-parse HEAD) &&
622 message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
623 git update-ref -m "$message" $head_name $newhead $orig_head &&
625 -m "$GIT_REFLOG_ACTION: returning to $head_name" \
629 test ! -f "$state_dir"/verbose ||
630 git diff-tree --stat $orig_head..HEAD
633 test -s "$rewritten_list" &&
634 git notes copy --for-rewrite=rebase < "$rewritten_list" ||
635 true # we don't care if this copying failed
637 if test -x "$GIT_DIR"/hooks/post-rewrite &&
638 test -s "$rewritten_list"; then
639 "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
640 true # we don't care if this hook failed
642 warn "Successfully rebased and updated $head_name."
644 return 1 # not failure; just to break the do_rest loop
647 # can only return 0, when the infinite loop breaks
655 # skip picking commits whose parents are unchanged
656 skip_unnecessary_picks () {
658 while read -r command rest
660 # fd=3 means we skip the command
661 case "$fd,$command" in
663 # pick a commit whose parent is current $onto -> skip
665 case "$(git rev-parse --verify --quiet "$sha1"^)" in
681 printf '%s\n' "$command${rest:+ }$rest" >&$fd
682 done <"$todo" >"$todo.new" 3>>"$done" &&
683 mv -f "$todo".new "$todo" &&
684 case "$(peek_next_command)" in
686 record_in_rewritten "$onto"
689 die "Could not skip unnecessary pick commands"
692 transform_todo_ids () {
693 while read -r command rest
696 "$comment_char"* | exec)
697 # Be careful for oddball commands like 'exec'
698 # that do not have a SHA-1 at the beginning of $rest.
701 sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) &&
702 rest="$sha1 ${rest#* }"
705 printf '%s\n' "$command${rest:+ }$rest"
706 done <"$todo" >"$todo.new" &&
707 mv -f "$todo.new" "$todo"
714 collapse_todo_ids() {
715 transform_todo_ids --short=7
718 # Rearrange the todo list that has both "pick sha1 msg" and
719 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
720 # comes immediately after the former, and change "pick" to
722 rearrange_squash () {
723 # extract fixup!/squash! lines and resolve any referenced sha1's
724 while read -r pick sha1 message
727 "squash! "*|"fixup! "*)
728 action="${message%%!*}"
731 # skip all squash! or fixup! (but save for later)
735 "squash! "*|"fixup! "*)
736 prefix="$prefix${rest%%!*},"
744 echo "$sha1 $action $prefix $rest"
745 # if it's a single word, try to resolve to a full sha1 and
746 # emit a second copy. This allows us to match on both message
748 if test "${rest#* }" = "$rest"; then
749 fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)"
750 if test -n "$fullsha"; then
751 # prefix the action to uniquely identify this line as
752 # intended for full sha1 match
753 echo "$sha1 +$action $prefix $fullsha"
758 test -s "$1.sq" || return
761 while read -r pick sha1 message
764 *" $sha1 "*) continue ;;
766 printf '%s\n' "$pick $sha1 $message"
768 while read -r squash action msg_prefix msg_content
771 *" $squash "*) continue ;;
777 # full sha1 prefix test
778 case "$msg_content" in "$sha1"*) emit=1;; esac ;;
780 # message prefix test
781 case "$message" in "$msg_content"*) emit=1;; esac ;;
783 if test $emit = 1; then
784 real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g")
785 printf '%s\n' "$action $squash ${real_prefix}$msg_content"
789 done >"$1.rearranged" <"$1"
790 cat "$1.rearranged" >"$1"
791 rm -f "$1.sq" "$1.rearranged"
794 # Add commands after a pick or after a squash/fixup serie
796 add_exec_commands () {
799 while read -r insn rest
807 printf "%s %s\n" "$insn" "$rest"
817 # do we have anything to commit?
818 if git diff-index --cached --quiet HEAD --
820 : Nothing to commit -- skip this
822 if ! test -f "$author_script"
824 die "You have staged changes in your working tree. If these changes are meant to be
825 squashed into the previous commit, run:
829 If they are meant to go into a new commit, run:
833 In both case, once you're done, continue with:
835 git rebase --continue
838 . "$author_script" ||
839 die "Error trying to find the author identity to amend commit"
842 current_head=$(git rev-parse --verify HEAD)
843 test "$current_head" = $(cat "$amend") ||
845 You have uncommitted changes in your working tree. Please, commit them
846 first and then run 'git rebase --continue' again."
847 do_with_author git commit --amend --no-verify -F "$msg" -e ||
848 die "Could not commit staged changes."
850 do_with_author git commit --no-verify -F "$msg" -e ||
851 die "Could not commit staged changes."
855 record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
857 require_clean_work_tree "rebase"
868 git stripspace --strip-comments <"$todo" >"$todo".new
869 mv -f "$todo".new "$todo"
872 git stripspace --comment-lines >>"$todo" <<\EOF
874 You are editing the todo file of an ongoing interactive rebase.
875 To continue rebase after editing, run:
876 git rebase --continue
880 git_sequence_editor "$todo" ||
881 die "Could not execute editor"
888 git var GIT_COMMITTER_IDENT >/dev/null ||
889 die "You need to set your committer info first"
891 comment_for_reflog start
893 if test ! -z "$switch_to"
895 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
896 output git checkout "$switch_to" -- ||
897 die "Could not checkout $switch_to"
899 comment_for_reflog start
902 orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
903 mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
905 : > "$state_dir"/interactive || die "Could not mark as interactive"
907 if test t = "$preserve_merges"
909 if test -z "$rebase_root"
911 mkdir "$rewritten" &&
912 for c in $(git merge-base --all $orig_head $upstream)
914 echo $onto > "$rewritten"/$c ||
915 die "Could not init rewritten commits"
918 mkdir "$rewritten" &&
919 echo $onto > "$rewritten"/root ||
920 die "Could not init rewritten commits"
922 # No cherry-pick because our first pass is to determine
923 # parents to rewrite and skipping dropped commits would
924 # prematurely end our probe
927 merges_option="--no-merges --cherry-pick"
930 shorthead=$(git rev-parse --short $orig_head)
931 shortonto=$(git rev-parse --short $onto)
932 if test -z "$rebase_root"
933 # this is now equivalent to ! -z "$upstream"
935 shortupstream=$(git rev-parse --short $upstream)
936 revisions=$upstream...$orig_head
937 shortrevisions=$shortupstream..$shorthead
939 revisions=$onto...$orig_head
940 shortrevisions=$shorthead
942 git rev-list $merges_option --pretty=oneline --abbrev-commit \
943 --abbrev=7 --reverse --left-right --topo-order \
946 while read -r shortsha1 rest
949 if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
951 comment_out="$comment_char "
956 if test t != "$preserve_merges"
958 printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
960 sha1=$(git rev-parse $shortsha1)
961 if test -z "$rebase_root"
964 for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
966 if test -f "$rewritten"/$p
974 if test f = "$preserve"
976 touch "$rewritten"/$sha1
977 printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
982 # Watch for commits that been dropped by --cherry-pick
983 if test t = "$preserve_merges"
986 # Save all non-cherry-picked changes
987 git rev-list $revisions --left-right --cherry-pick | \
988 sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
989 # Now all commits and note which ones are missing in
990 # not-cherry-picks and hence being dropped
991 git rev-list $revisions |
994 if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
996 # Use -f2 because if rev-list is telling us this commit is
997 # not worthwhile, we don't want to track its multiple heads,
998 # just the history of its first-parent for others that will
999 # be rebasing on top of it
1000 git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
1001 short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
1002 sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1003 rm "$rewritten"/$rev
1008 test -s "$todo" || echo noop >> "$todo"
1009 test -n "$autosquash" && rearrange_squash "$todo"
1010 test -n "$cmd" && add_exec_commands "$todo"
1014 $comment_char Rebase $shortrevisions onto $shortonto
1017 git stripspace --comment-lines >>"$todo" <<\EOF
1019 However, if you remove everything, the rebase will be aborted.
1023 if test -z "$keep_empty"
1025 printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
1029 has_action "$todo" ||
1030 die_abort "Nothing to do"
1032 cp "$todo" "$todo".backup
1033 git_sequence_editor "$todo" ||
1034 die_abort "Could not execute editor"
1036 has_action "$todo" ||
1037 die_abort "Nothing to do"
1041 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
1043 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
1044 output git checkout $onto || die_abort "could not detach HEAD"
1045 git update-ref ORIG_HEAD $orig_head