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 no-ff cherry-pick all commits, even if unchanged
24 m,merge always used (no-op)
25 i,interactive always used (no-op)
27 continue continue rebasing process
28 abort abort rebasing process and restore original branch
29 skip skip current patch and continue rebasing process
30 no-verify override pre-rebase hook from stopping the operation
31 verify allow pre-rebase hook to run
32 root rebase all reachable commmits up to the root(s)
33 autosquash move commits that begin with squash!/fixup! under -i
39 DOTEST="$GIT_DIR/rebase-merge"
41 # The file containing rebase commands, comments, and empty lines.
42 # This file is created by "git rebase -i" then edited by the user. As
43 # the lines are processed, they are removed from the front of this
44 # file and written to the tail of $DONE.
45 TODO="$DOTEST"/git-rebase-todo
47 # The rebase command lines that have already been processed. A line
48 # is moved here when it is first handled, before any associated user
52 # The commit message that is planned to be used for any changes that
53 # need to be committed following a user interaction.
56 # The file into which is accumulated the suggested commit message for
57 # squash/fixup commands. When the first of a series of squash/fixups
58 # is seen, the file is created and the commit message from the
59 # previous commit and from the first squash/fixup commit are written
60 # to it. The commit message for each subsequent squash/fixup commit
61 # is appended to the file as it is processed.
63 # The first line of the file is of the form
64 # # This is a combination of $COUNT commits.
65 # where $COUNT is the number of commits whose messages have been
66 # written to the file so far (including the initial "pick" commit).
67 # Each time that a commit message is processed, this line is read and
68 # updated. It is deleted just before the combined commit is made.
69 SQUASH_MSG="$DOTEST"/message-squash
71 # If the current series of squash/fixups has not yet included a squash
72 # command, then this file exists and holds the commit message of the
73 # original "pick" commit. (If the series ends without a "squash"
74 # command, then this can be used as the commit message of the combined
75 # commit without opening the editor.)
76 FIXUP_MSG="$DOTEST"/message-fixup
78 # $REWRITTEN is the name of a directory containing files for each
79 # commit that is reachable by at least one merge base of $HEAD and
80 # $UPSTREAM. They are not necessarily rewritten, but their children
81 # might be. This ensures that commits on merged, but otherwise
82 # unrelated side branches are left alone. (Think "X" in the man page's
84 REWRITTEN="$DOTEST"/rewritten
86 DROPPED="$DOTEST"/dropped
88 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
89 # GIT_AUTHOR_DATE that will be used for the commit that is currently
91 AUTHOR_SCRIPT="$DOTEST"/author-script
93 # When an "edit" rebase command is being processed, the SHA1 of the
94 # commit to be edited is recorded in this file. When "git rebase
95 # --continue" is executed, if there are any staged changes then they
96 # will be amended to the HEAD commit, but only provided the HEAD
97 # commit is still the commit to be edited. When any other rebase
98 # command is processed, this file is deleted.
101 # For the post-rewrite hook, we make a list of rewritten commits and
102 # their new sha1s. The rewritten-pending list keeps the sha1s of
103 # commits that have been processed, but not committed yet,
104 # e.g. because they are waiting for a 'squash' command.
105 REWRITTEN_LIST="$DOTEST"/rewritten-list
106 REWRITTEN_PENDING="$DOTEST"/rewritten-pending
112 OK_TO_SKIP_PRE_REBASE=
115 test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
118 GIT_CHERRY_PICK_HELP="\
119 hint: after resolving the conflicts, mark the corrected paths
120 hint: with 'git add <paths>' and run 'git rebase --continue'"
121 export GIT_CHERRY_PICK_HELP
124 printf '%s\n' "$*" >&2
132 test $status != 0 && printf "%s\n" "$output"
141 # Output the commit message for the specified commit.
143 git cat-file commit "$1" | sed "1,/^$/d"
146 run_pre_rebase_hook () {
147 if test -z "$OK_TO_SKIP_PRE_REBASE" &&
148 test -x "$GIT_DIR/hooks/pre-rebase"
150 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
151 echo >&2 "The pre-rebase hook refused to rebase."
157 require_clean_work_tree () {
158 # test if working tree is dirty
159 git rev-parse --verify HEAD > /dev/null &&
160 git update-index --ignore-submodules --refresh &&
161 git diff-files --quiet --ignore-submodules &&
162 git diff-index --cached --quiet HEAD --ignore-submodules -- ||
163 die "Working tree is dirty"
166 ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
168 comment_for_reflog () {
169 case "$ORIG_REFLOG_ACTION" in
171 GIT_REFLOG_ACTION="rebase -i ($1)"
172 export GIT_REFLOG_ACTION
178 mark_action_done () {
179 sed -e 1q < "$TODO" >> "$DONE"
180 sed -e 1d < "$TODO" >> "$TODO".new
181 mv -f "$TODO".new "$TODO"
182 count=$(sane_grep -c '^[^#]' < "$DONE")
183 total=$(($count+$(sane_grep -c '^[^#]' < "$TODO")))
184 if test "$last_count" != "$count"
187 printf "Rebasing (%d/%d)\r" $count $total
188 test -z "$VERBOSE" || echo
193 sha1_and_parents="$(git rev-list --parents -1 "$1")"
194 case "$sha1_and_parents" in
196 git diff --cc $sha1_and_parents
199 git diff-tree -p "$1^!"
204 esac > "$DOTEST"/patch
206 commit_message "$1" > "$MSG"
207 test -f "$AUTHOR_SCRIPT" ||
208 get_author_ident_from_commit "$1" > "$AUTHOR_SCRIPT"
212 echo "$1" > "$DOTEST"/stopped-sha
224 sane_grep '^[^#]' "$1" >/dev/null
227 # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
228 # GIT_AUTHOR_DATE exported from the current environment.
231 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
238 case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
239 case "$NEVER_FF" in '') ;; ?*) ff= ;; esac
240 output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
241 test -d "$REWRITTEN" &&
242 pick_one_preserving_merges "$@" && return
243 if test -n "$REBASE_ROOT"
245 output git cherry-pick "$@"
248 output git cherry-pick $ff "$@"
251 pick_one_preserving_merges () {
262 sha1=$(git rev-parse $sha1)
264 if test -f "$DOTEST"/current-commit
266 if test "$fast_forward" = t
268 while read current_commit
270 git rev-parse HEAD > "$REWRITTEN"/$current_commit
271 done <"$DOTEST"/current-commit
272 rm "$DOTEST"/current-commit ||
273 die "Cannot write current commit's replacement sha1"
277 echo $sha1 >> "$DOTEST"/current-commit
279 # rewrite parents; if none were rewritten, we can fast-forward.
281 pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
282 if test "$pend" = " "
286 while [ "$pend" != "" ]
288 p=$(expr "$pend" : ' \([^ ]*\)')
291 if test -f "$REWRITTEN"/$p
293 new_p=$(cat "$REWRITTEN"/$p)
295 # If the todo reordered commits, and our parent is marked for
296 # rewriting, but hasn't been gotten to yet, assume the user meant to
297 # drop it on top of the current HEAD
300 new_p=$(git rev-parse HEAD)
303 test $p != $new_p && fast_forward=f
304 case "$new_parents" in
306 ;; # do nothing; that parent is already there
308 new_parents="$new_parents $new_p"
312 if test -f "$DROPPED"/$p
315 replacement="$(cat "$DROPPED"/$p)"
316 test -z "$replacement" && replacement=root
317 pend=" $replacement$pend"
319 new_parents="$new_parents $p"
323 case $fast_forward in
325 output warn "Fast-forward to $sha1"
326 output git reset --hard $sha1 ||
327 die "Cannot fast-forward to $sha1"
330 first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
334 # detach HEAD to current parent
335 output git checkout $first_parent 2> /dev/null ||
336 die "Cannot move HEAD to $first_parent"
339 case "$new_parents" in
341 test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
344 author_script=$(get_author_ident_from_commit $sha1)
345 eval "$author_script"
346 msg="$(commit_message $sha1)"
347 # No point in merging the first parent, that's HEAD
348 new_parents=${new_parents# $first_parent}
349 if ! do_with_author output \
350 git merge $STRATEGY -m "$msg" $new_parents
352 printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
353 die_with_patch $sha1 "Error redoing merge $sha1"
355 echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
358 output git cherry-pick "$@" ||
359 die_with_patch $sha1 "Could not pick $sha1"
368 *1[0-9]|*[04-9]) echo "$1"th;;
375 update_squash_messages () {
376 if test -f "$SQUASH_MSG"; then
377 mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit
379 -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
380 -e "q" < "$SQUASH_MSG".bak)+1))
382 echo "# This is a combination of $COUNT commits."
383 sed -e 1d -e '2,/^./{
385 }' <"$SQUASH_MSG".bak
388 commit_message HEAD > "$FIXUP_MSG" || die "Cannot write $FIXUP_MSG"
391 echo "# This is a combination of 2 commits."
392 echo "# The first commit's message is:"
401 echo "# This is the $(nth_string $COUNT) commit message:"
407 echo "# The $(nth_string $COUNT) commit message will be skipped:"
409 commit_message $2 | sed -e 's/^/# /'
414 peek_next_command () {
415 sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO"
418 # A squash/fixup has failed. Prepare the long version of the squash
419 # commit message, then die_with_patch. This code path requires the
420 # user to edit the combined commit message for all commits that have
421 # been squashed/fixedup so far. So also erase the old squash
422 # messages, effectively causing the combined commit to be used as the
423 # new basis for any further squash/fixups. Args: sha1 rest
424 die_failed_squash() {
425 mv "$SQUASH_MSG" "$MSG" || exit
427 cp "$MSG" "$GIT_DIR"/MERGE_MSG || exit
429 warn "Could not apply $1... $2"
433 flush_rewritten_pending() {
434 test -s "$REWRITTEN_PENDING" || return
435 newsha1="$(git rev-parse HEAD^0)"
436 sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST"
437 rm -f "$REWRITTEN_PENDING"
440 record_in_rewritten() {
441 oldsha1="$(git rev-parse $1)"
442 echo "$oldsha1" >> "$REWRITTEN_PENDING"
444 case "$(peek_next_command)" in
448 flush_rewritten_pending
454 rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit
455 read -r command sha1 rest < "$TODO"
461 comment_for_reflog pick
465 die_with_patch $sha1 "Could not apply $sha1... $rest"
466 record_in_rewritten $sha1
469 comment_for_reflog reword
473 die_with_patch $sha1 "Could not apply $sha1... $rest"
474 git commit --amend --no-post-rewrite
475 record_in_rewritten $sha1
478 comment_for_reflog edit
482 die_with_patch $sha1 "Could not apply $sha1... $rest"
483 echo "$sha1" > "$DOTEST"/stopped-sha
485 git rev-parse --verify HEAD > "$AMEND"
486 warn "Stopped at $sha1... $rest"
487 warn "You can amend the commit now, with"
489 warn " git commit --amend"
491 warn "Once you are satisfied with your changes, run"
493 warn " git rebase --continue"
506 comment_for_reflog $squash_style
508 test -f "$DONE" && has_action "$DONE" ||
509 die "Cannot '$squash_style' without a previous commit"
512 update_squash_messages $squash_style $sha1
513 author_script=$(get_author_ident_from_commit HEAD)
514 echo "$author_script" > "$AUTHOR_SCRIPT"
515 eval "$author_script"
516 output git reset --soft HEAD^
517 pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
518 case "$(peek_next_command)" in
520 # This is an intermediate commit; its message will only be
521 # used in case of trouble. So use the long version:
522 do_with_author output git commit --no-verify -F "$SQUASH_MSG" ||
523 die_failed_squash $sha1 "$rest"
526 # This is the final command of this squash/fixup group
527 if test -f "$FIXUP_MSG"
529 do_with_author git commit --no-verify -F "$FIXUP_MSG" ||
530 die_failed_squash $sha1 "$rest"
532 cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG || exit
533 rm -f "$GIT_DIR"/MERGE_MSG
534 do_with_author git commit --no-verify -e ||
535 die_failed_squash $sha1 "$rest"
537 rm -f "$SQUASH_MSG" "$FIXUP_MSG"
540 record_in_rewritten $sha1
543 read -r command rest < "$TODO"
545 printf 'Executing: %s\n' "$rest"
546 # "exec" command doesn't take a sha1 in the todo-list.
547 # => can't just use $sha1 here.
548 git rev-parse --verify HEAD > "$DOTEST"/stopped-sha
549 ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
551 if test "$status" -ne 0
553 warn "Execution failed: $rest"
554 warn "You can fix the problem, and then run"
556 warn " git rebase --continue"
560 # Run in subshell because require_clean_work_tree can die.
561 if ! (require_clean_work_tree)
563 warn "Commit or stash your changes, and then run"
565 warn " git rebase --continue"
571 warn "Unknown command: $command $sha1 $rest"
572 if git rev-parse --verify -q "$sha1" >/dev/null
574 die_with_patch $sha1 "Please fix this in the file $TODO."
576 die "Please fix this in the file $TODO."
580 test -s "$TODO" && return
582 comment_for_reflog finish &&
583 HEADNAME=$(cat "$DOTEST"/head-name) &&
584 OLDHEAD=$(cat "$DOTEST"/head) &&
585 SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
586 NEWHEAD=$(git rev-parse HEAD) &&
589 message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
590 git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
591 git symbolic-ref HEAD $HEADNAME
594 test ! -f "$DOTEST"/verbose ||
595 git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
598 test -s "$REWRITTEN_LIST" &&
599 git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" ||
600 true # we don't care if this copying failed
602 if test -x "$GIT_DIR"/hooks/post-rewrite &&
603 test -s "$REWRITTEN_LIST"; then
604 "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
605 true # we don't care if this hook failed
609 warn "Successfully rebased and updated $HEADNAME."
621 # skip picking commits whose parents are unchanged
622 skip_unnecessary_picks () {
624 while read -r command rest
626 # fd=3 means we skip the command
627 case "$fd,$command" in
629 # pick a commit whose parent is current $ONTO -> skip
631 case "$(git rev-parse --verify --quiet "$sha1"^)" in
647 printf '%s\n' "$command${rest:+ }$rest" >&$fd
648 done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
649 mv -f "$TODO".new "$TODO" &&
650 case "$(peek_next_command)" in
652 record_in_rewritten "$ONTO"
655 die "Could not skip unnecessary pick commands"
658 # check if no other options are set
660 test $# -eq 2 -a "$2" = '--' &&
662 test -z "$PRESERVE_MERGES" &&
663 test -z "$STRATEGY" &&
667 get_saved_options () {
668 test -d "$REWRITTEN" && PRESERVE_MERGES=t
669 test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
670 test -f "$DOTEST"/verbose && VERBOSE=t
671 test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
674 # Rearrange the todo list that has both "pick sha1 msg" and
675 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
676 # comes immediately after the former, and change "pick" to
678 rearrange_squash () {
679 sed -n -e 's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p' \
680 -e 's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p' \
682 test -s "$1.sq" || return
685 while read -r pick sha1 message
688 *" $sha1 "*) continue ;;
690 printf '%s\n' "$pick $sha1 $message"
691 while read -r squash action msg
695 printf '%s\n' "$action $squash $action! $msg"
700 done >"$1.rearranged" <"$1"
701 cat "$1.rearranged" >"$1"
702 rm -f "$1.sq" "$1.rearranged"
710 if left=${1%...*} right=${1#*...} &&
711 onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
721 git rev-parse --verify "$1^0"
728 OK_TO_SKIP_PRE_REBASE=yes
731 OK_TO_SKIP_PRE_REBASE=
734 is_standalone "$@" || usage
736 comment_for_reflog continue
738 test -d "$DOTEST" || die "No interactive rebase running"
741 git rev-parse --verify HEAD >/dev/null ||
742 die "Cannot read HEAD"
743 git update-index --ignore-submodules --refresh &&
744 git diff-files --quiet --ignore-submodules ||
745 die "Working tree is dirty"
747 # do we have anything to commit?
748 if git diff-index --cached --quiet --ignore-submodules HEAD --
750 : Nothing to commit -- skip this
752 . "$AUTHOR_SCRIPT" ||
753 die "Cannot find the author identity"
757 amend=$(git rev-parse --verify HEAD)
758 test "$amend" = $(cat "$AMEND") ||
760 You have uncommitted changes in your working tree. Please, commit them
761 first and then run 'git rebase --continue' again."
762 git reset --soft HEAD^ ||
763 die "Cannot rewind the HEAD"
765 do_with_author git commit --no-verify -F "$MSG" -e || {
766 test -n "$amend" && git reset --soft $amend
767 die "Could not commit staged changes."
771 record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
773 require_clean_work_tree
777 is_standalone "$@" || usage
779 comment_for_reflog abort
782 test -d "$DOTEST" || die "No interactive rebase running"
784 HEADNAME=$(cat "$DOTEST"/head-name)
785 HEAD=$(cat "$DOTEST"/head)
788 git symbolic-ref HEAD $HEADNAME
791 output git reset --hard $HEAD &&
796 is_standalone "$@" || usage
798 comment_for_reflog skip
801 test -d "$DOTEST" || die "No interactive rebase running"
803 output git reset --hard && do_rest
808 STRATEGY="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
817 # we use merge anyway
842 ONTO=$(parse_onto "$1") ||
843 die "Does not point to a valid commit: $1"
847 test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
848 test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
850 die "Interactive rebase already started"
852 git var GIT_COMMITTER_IDENT >/dev/null ||
853 die "You need to set your committer info first"
855 if test -z "$REBASE_ROOT"
858 UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
859 test -z "$ONTO" && ONTO=$UPSTREAM
865 die "You must specify --onto when using --root"
867 run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
869 comment_for_reflog start
871 require_clean_work_tree
875 output git checkout "$1" ||
876 die "Could not checkout $1"
879 HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
880 mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
882 : > "$DOTEST"/interactive || die "Could not mark as interactive"
883 git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
884 echo "detached HEAD" > "$DOTEST"/head-name
886 echo $HEAD > "$DOTEST"/head
887 case "$REBASE_ROOT" in
889 rm -f "$DOTEST"/rebase-root ;;
891 : >"$DOTEST"/rebase-root ;;
893 echo $ONTO > "$DOTEST"/onto
894 test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
895 test t = "$VERBOSE" && : > "$DOTEST"/verbose
896 if test t = "$PRESERVE_MERGES"
898 if test -z "$REBASE_ROOT"
900 mkdir "$REWRITTEN" &&
901 for c in $(git merge-base --all $HEAD $UPSTREAM)
903 echo $ONTO > "$REWRITTEN"/$c ||
904 die "Could not init rewritten commits"
907 mkdir "$REWRITTEN" &&
908 echo $ONTO > "$REWRITTEN"/root ||
909 die "Could not init rewritten commits"
911 # No cherry-pick because our first pass is to determine
912 # parents to rewrite and skipping dropped commits would
913 # prematurely end our probe
915 first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
917 MERGES_OPTION="--no-merges --cherry-pick"
920 SHORTHEAD=$(git rev-parse --short $HEAD)
921 SHORTONTO=$(git rev-parse --short $ONTO)
922 if test -z "$REBASE_ROOT"
923 # this is now equivalent to ! -z "$UPSTREAM"
925 SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
926 REVISIONS=$UPSTREAM...$HEAD
927 SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
929 REVISIONS=$ONTO...$HEAD
930 SHORTREVISIONS=$SHORTHEAD
932 git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
933 --abbrev=7 --reverse --left-right --topo-order \
936 while read -r shortsha1 rest
938 if test t != "$PRESERVE_MERGES"
940 printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
942 sha1=$(git rev-parse $shortsha1)
943 if test -z "$REBASE_ROOT"
946 for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
948 if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
956 if test f = "$preserve"
958 touch "$REWRITTEN"/$sha1
959 printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
964 # Watch for commits that been dropped by --cherry-pick
965 if test t = "$PRESERVE_MERGES"
968 # Save all non-cherry-picked changes
969 git rev-list $REVISIONS --left-right --cherry-pick | \
970 sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
971 # Now all commits and note which ones are missing in
972 # not-cherry-picks and hence being dropped
973 git rev-list $REVISIONS |
976 if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
978 # Use -f2 because if rev-list is telling us this commit is
979 # not worthwhile, we don't want to track its multiple heads,
980 # just the history of its first-parent for others that will
981 # be rebasing on top of it
982 git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
983 short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
984 sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
990 test -s "$TODO" || echo noop >> "$TODO"
991 test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
992 cat >> "$TODO" << EOF
994 # Rebase $SHORTREVISIONS onto $SHORTONTO
997 # p, pick = use commit
998 # r, reword = use commit, but edit the commit message
999 # e, edit = use commit, but stop for amending
1000 # s, squash = use commit, but meld into previous commit
1001 # f, fixup = like "squash", but discard this commit's log message
1002 # x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
1004 # If you remove a line here THAT COMMIT WILL BE LOST.
1005 # However, if you remove everything, the rebase will be aborted.
1009 has_action "$TODO" ||
1010 die_abort "Nothing to do"
1012 cp "$TODO" "$TODO".backup
1013 git_editor "$TODO" ||
1014 die_abort "Could not execute editor"
1016 has_action "$TODO" ||
1017 die_abort "Nothing to do"
1019 test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
1021 output git checkout $ONTO || die_abort "could not detach HEAD"
1022 git update-ref ORIG_HEAD $HEAD