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 root rebase all reachable commmits up to the root(s)
32 autosquash move commits that begin with squash!/fixup! under -i
38 DOTEST
="$GIT_DIR/rebase-merge"
40 # The file containing rebase commands, comments, and empty lines.
41 # This file is created by "git rebase -i" then edited by the user. As
42 # the lines are processed, they are removed from the front of this
43 # file and written to the tail of $DONE.
44 TODO
="$DOTEST"/git-rebase-todo
46 # The rebase command lines that have already been processed. A line
47 # is moved here when it is first handled, before any associated user
51 # The commit message that is planned to be used for any changes that
52 # need to be committed following a user interaction.
55 # The file into which is accumulated the suggested commit message for
56 # squash/fixup commands. When the first of a series of squash/fixups
57 # is seen, the file is created and the commit message from the
58 # previous commit and from the first squash/fixup commit are written
59 # to it. The commit message for each subsequent squash/fixup commit
60 # is appended to the file as it is processed.
62 # The first line of the file is of the form
63 # # This is a combination of $COUNT commits.
64 # where $COUNT is the number of commits whose messages have been
65 # written to the file so far (including the initial "pick" commit).
66 # Each time that a commit message is processed, this line is read and
67 # updated. It is deleted just before the combined commit is made.
68 SQUASH_MSG
="$DOTEST"/message-squash
70 # If the current series of squash/fixups has not yet included a squash
71 # command, then this file exists and holds the commit message of the
72 # original "pick" commit. (If the series ends without a "squash"
73 # command, then this can be used as the commit message of the combined
74 # commit without opening the editor.)
75 FIXUP_MSG
="$DOTEST"/message-fixup
77 # $REWRITTEN is the name of a directory containing files for each
78 # commit that is reachable by at least one merge base of $HEAD and
79 # $UPSTREAM. They are not necessarily rewritten, but their children
80 # might be. This ensures that commits on merged, but otherwise
81 # unrelated side branches are left alone. (Think "X" in the man page's
83 REWRITTEN
="$DOTEST"/rewritten
85 DROPPED
="$DOTEST"/dropped
87 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
88 # GIT_AUTHOR_DATE that will be used for the commit that is currently
90 AUTHOR_SCRIPT
="$DOTEST"/author-script
92 # When an "edit" rebase command is being processed, the SHA1 of the
93 # commit to be edited is recorded in this file. When "git rebase
94 # --continue" is executed, if there are any staged changes then they
95 # will be amended to the HEAD commit, but only provided the HEAD
96 # commit is still the commit to be edited. When any other rebase
97 # command is processed, this file is deleted.
100 # For the post-rewrite hook, we make a list of rewritten commits and
101 # their new sha1s. The rewritten-pending list keeps the sha1s of
102 # commits that have been processed, but not committed yet,
103 # e.g. because they are waiting for a 'squash' command.
104 REWRITTEN_LIST
="$DOTEST"/rewritten-list
105 REWRITTEN_PENDING
="$DOTEST"/rewritten-pending
111 OK_TO_SKIP_PRE_REBASE
=
114 test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH
=t
117 GIT_CHERRY_PICK_HELP
="\
118 hint: after resolving the conflicts, mark the corrected paths
119 hint: with 'git add <paths>' and run 'git rebase --continue'"
120 export GIT_CHERRY_PICK_HELP
123 printf '%s\n' "$*" >&2
131 test $status != 0 && printf "%s\n" "$output"
140 # Output the commit message for the specified commit.
142 git cat-file commit
"$1" |
sed "1,/^$/d"
145 run_pre_rebase_hook
() {
146 if test -z "$OK_TO_SKIP_PRE_REBASE" &&
147 test -x "$GIT_DIR/hooks/pre-rebase"
149 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
{
150 echo >&2 "The pre-rebase hook refused to rebase."
157 ORIG_REFLOG_ACTION
="$GIT_REFLOG_ACTION"
159 comment_for_reflog
() {
160 case "$ORIG_REFLOG_ACTION" in
162 GIT_REFLOG_ACTION
="rebase -i ($1)"
163 export GIT_REFLOG_ACTION
169 mark_action_done
() {
170 sed -e 1q
< "$TODO" >> "$DONE"
171 sed -e 1d
< "$TODO" >> "$TODO".new
172 mv -f "$TODO".new
"$TODO"
173 count
=$
(sane_grep
-c '^[^#]' < "$DONE")
174 total
=$
(($count+$
(sane_grep
-c '^[^#]' < "$TODO")))
175 if test "$last_count" != "$count"
178 printf "Rebasing (%d/%d)\r" $count $total
179 test -z "$VERBOSE" ||
echo
184 sha1_and_parents
="$(git rev-list --parents -1 "$1")"
185 case "$sha1_and_parents" in
187 git
diff --cc $sha1_and_parents
190 git diff-tree
-p "$1^!"
195 esac > "$DOTEST"/patch
197 commit_message
"$1" > "$MSG"
198 test -f "$AUTHOR_SCRIPT" ||
199 get_author_ident_from_commit
"$1" > "$AUTHOR_SCRIPT"
203 echo "$1" > "$DOTEST"/stopped-sha
215 sane_grep
'^[^#]' "$1" >/dev
/null
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
229 case "$1" in -n) sha1
=$2; ff
= ;; *) sha1
=$1 ;; esac
230 case "$NEVER_FF" in '') ;; ?
*) ff
= ;; esac
231 output git rev-parse
--verify $sha1 || die
"Invalid commit name: $sha1"
232 test -d "$REWRITTEN" &&
233 pick_one_preserving_merges
"$@" && return
234 if test -n "$REBASE_ROOT"
236 output git cherry-pick
"$@"
239 output git cherry-pick
$ff "$@"
242 pick_one_preserving_merges
() {
253 sha1
=$
(git rev-parse
$sha1)
255 if test -f "$DOTEST"/current-commit
257 if test "$fast_forward" = t
259 while read current_commit
261 git rev-parse HEAD
> "$REWRITTEN"/$current_commit
262 done <"$DOTEST"/current-commit
263 rm "$DOTEST"/current-commit ||
264 die
"Cannot write current commit's replacement sha1"
268 echo $sha1 >> "$DOTEST"/current-commit
270 # rewrite parents; if none were rewritten, we can fast-forward.
272 pend
=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
273 if test "$pend" = " "
277 while [ "$pend" != "" ]
279 p
=$
(expr "$pend" : ' \([^ ]*\)')
282 if test -f "$REWRITTEN"/$p
284 new_p
=$
(cat "$REWRITTEN"/$p)
286 # If the todo reordered commits, and our parent is marked for
287 # rewriting, but hasn't been gotten to yet, assume the user meant to
288 # drop it on top of the current HEAD
291 new_p
=$
(git rev-parse HEAD
)
294 test $p != $new_p && fast_forward
=f
295 case "$new_parents" in
297 ;; # do nothing; that parent is already there
299 new_parents
="$new_parents $new_p"
303 if test -f "$DROPPED"/$p
306 replacement
="$(cat "$DROPPED"/$p)"
307 test -z "$replacement" && replacement
=root
308 pend
=" $replacement$pend"
310 new_parents
="$new_parents $p"
314 case $fast_forward in
316 output warn
"Fast-forward to $sha1"
317 output git
reset --hard $sha1 ||
318 die
"Cannot fast-forward to $sha1"
321 first_parent
=$
(expr "$new_parents" : ' \([^ ]*\)')
325 # detach HEAD to current parent
326 output git checkout
$first_parent 2> /dev
/null ||
327 die
"Cannot move HEAD to $first_parent"
330 case "$new_parents" in
332 test "a$1" = a-n
&& die
"Refusing to squash a merge: $sha1"
335 author_script
=$
(get_author_ident_from_commit
$sha1)
336 eval "$author_script"
337 msg
="$(commit_message $sha1)"
338 # No point in merging the first parent, that's HEAD
339 new_parents
=${new_parents# $first_parent}
340 if ! do_with_author output \
341 git merge
$STRATEGY -m "$msg" $new_parents
343 printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
344 die_with_patch
$sha1 "Error redoing merge $sha1"
346 echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
349 output git cherry-pick
"$@" ||
350 die_with_patch
$sha1 "Could not pick $sha1"
359 *1[0-9]|
*[04-9]) echo "$1"th
;;
366 update_squash_messages
() {
367 if test -f "$SQUASH_MSG"; then
368 mv "$SQUASH_MSG" "$SQUASH_MSG".bak ||
exit
370 -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
371 -e "q" < "$SQUASH_MSG".bak
)+1))
373 echo "# This is a combination of $COUNT commits."
374 sed -e 1d
-e '2,/^./{
376 }' <"$SQUASH_MSG".bak
379 commit_message HEAD
> "$FIXUP_MSG" || die
"Cannot write $FIXUP_MSG"
382 echo "# This is a combination of 2 commits."
383 echo "# The first commit's message is:"
392 echo "# This is the $(nth_string $COUNT) commit message:"
398 echo "# The $(nth_string $COUNT) commit message will be skipped:"
400 commit_message
$2 |
sed -e 's/^/# /'
405 peek_next_command
() {
406 sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO"
409 # A squash/fixup has failed. Prepare the long version of the squash
410 # commit message, then die_with_patch. This code path requires the
411 # user to edit the combined commit message for all commits that have
412 # been squashed/fixedup so far. So also erase the old squash
413 # messages, effectively causing the combined commit to be used as the
414 # new basis for any further squash/fixups. Args: sha1 rest
415 die_failed_squash
() {
416 mv "$SQUASH_MSG" "$MSG" ||
exit
418 cp "$MSG" "$GIT_DIR"/MERGE_MSG ||
exit
420 warn
"Could not apply $1... $2"
424 flush_rewritten_pending
() {
425 test -s "$REWRITTEN_PENDING" ||
return
426 newsha1
="$(git rev-parse HEAD^0)"
427 sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST"
428 rm -f "$REWRITTEN_PENDING"
431 record_in_rewritten
() {
432 oldsha1
="$(git rev-parse $1)"
433 echo "$oldsha1" >> "$REWRITTEN_PENDING"
435 case "$(peek_next_command)" in
439 flush_rewritten_pending
445 rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" ||
exit
446 read -r command sha1 rest
< "$TODO"
452 comment_for_reflog pick
456 die_with_patch
$sha1 "Could not apply $sha1... $rest"
457 record_in_rewritten
$sha1
460 comment_for_reflog reword
464 die_with_patch
$sha1 "Could not apply $sha1... $rest"
465 git commit
--amend --no-post-rewrite
466 record_in_rewritten
$sha1
469 comment_for_reflog edit
473 die_with_patch
$sha1 "Could not apply $sha1... $rest"
474 echo "$sha1" > "$DOTEST"/stopped-sha
476 git rev-parse
--verify HEAD
> "$AMEND"
477 warn
"Stopped at $sha1... $rest"
478 warn
"You can amend the commit now, with"
480 warn
" git commit --amend"
482 warn
"Once you are satisfied with your changes, run"
484 warn
" git rebase --continue"
497 comment_for_reflog
$squash_style
499 test -f "$DONE" && has_action
"$DONE" ||
500 die
"Cannot '$squash_style' without a previous commit"
503 update_squash_messages
$squash_style $sha1
504 author_script
=$
(get_author_ident_from_commit HEAD
)
505 echo "$author_script" > "$AUTHOR_SCRIPT"
506 eval "$author_script"
507 output git
reset --soft HEAD^
508 pick_one
-n $sha1 || die_failed_squash
$sha1 "$rest"
509 case "$(peek_next_command)" in
511 # This is an intermediate commit; its message will only be
512 # used in case of trouble. So use the long version:
513 do_with_author output git commit
--no-verify -F "$SQUASH_MSG" ||
514 die_failed_squash
$sha1 "$rest"
517 # This is the final command of this squash/fixup group
518 if test -f "$FIXUP_MSG"
520 do_with_author git commit
--no-verify -F "$FIXUP_MSG" ||
521 die_failed_squash
$sha1 "$rest"
523 cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG ||
exit
524 rm -f "$GIT_DIR"/MERGE_MSG
525 do_with_author git commit
--no-verify -e ||
526 die_failed_squash
$sha1 "$rest"
528 rm -f "$SQUASH_MSG" "$FIXUP_MSG"
531 record_in_rewritten
$sha1
534 read -r command rest
< "$TODO"
536 printf 'Executing: %s\n' "$rest"
537 # "exec" command doesn't take a sha1 in the todo-list.
538 # => can't just use $sha1 here.
539 git rev-parse
--verify HEAD
> "$DOTEST"/stopped-sha
540 ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
542 if test "$status" -ne 0
544 warn
"Execution failed: $rest"
545 warn
"You can fix the problem, and then run"
547 warn
" git rebase --continue"
551 # Run in subshell because require_clean_work_tree can die.
552 if ! (require_clean_work_tree
"rebase")
554 warn
"Commit or stash your changes, and then run"
556 warn
" git rebase --continue"
562 warn
"Unknown command: $command $sha1 $rest"
563 if git rev-parse
--verify -q "$sha1" >/dev
/null
565 die_with_patch
$sha1 "Please fix this in the file $TODO."
567 die
"Please fix this in the file $TODO."
571 test -s "$TODO" && return
573 comment_for_reflog finish
&&
574 HEADNAME
=$
(cat "$DOTEST"/head-name
) &&
575 OLDHEAD
=$
(cat "$DOTEST"/head) &&
576 SHORTONTO
=$
(git rev-parse
--short $
(cat "$DOTEST"/onto
)) &&
577 NEWHEAD
=$
(git rev-parse HEAD
) &&
580 message
="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
581 git update-ref
-m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
582 git symbolic-ref HEAD
$HEADNAME
585 test ! -f "$DOTEST"/verbose ||
586 git diff-tree
--stat $
(cat "$DOTEST"/head)..HEAD
589 test -s "$REWRITTEN_LIST" &&
590 git notes copy
--for-rewrite=rebase
< "$REWRITTEN_LIST" ||
591 true
# we don't care if this copying failed
593 if test -x "$GIT_DIR"/hooks
/post-rewrite
&&
594 test -s "$REWRITTEN_LIST"; then
595 "$GIT_DIR"/hooks
/post-rewrite rebase
< "$REWRITTEN_LIST"
596 true
# we don't care if this hook failed
600 warn
"Successfully rebased and updated $HEADNAME."
612 # skip picking commits whose parents are unchanged
613 skip_unnecessary_picks
() {
615 while read -r command rest
617 # fd=3 means we skip the command
618 case "$fd,$command" in
620 # pick a commit whose parent is current $ONTO -> skip
622 case "$(git rev-parse --verify --quiet "$sha1"^)" in
638 printf '%s\n' "$command${rest:+ }$rest" >&$fd
639 done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
640 mv -f "$TODO".new
"$TODO" &&
641 case "$(peek_next_command)" in
643 record_in_rewritten
"$ONTO"
646 die
"Could not skip unnecessary pick commands"
649 # check if no other options are set
651 test $# -eq 2 -a "$2" = '--' &&
653 test -z "$PRESERVE_MERGES" &&
654 test -z "$STRATEGY" &&
658 get_saved_options
() {
659 test -d "$REWRITTEN" && PRESERVE_MERGES
=t
660 test -f "$DOTEST"/strategy
&& STRATEGY
="$(cat "$DOTEST"/strategy)"
661 test -f "$DOTEST"/verbose
&& VERBOSE
=t
662 test -f "$DOTEST"/rebase-root
&& REBASE_ROOT
=t
665 # Rearrange the todo list that has both "pick sha1 msg" and
666 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
667 # comes immediately after the former, and change "pick" to
669 rearrange_squash
() {
670 sed -n -e 's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p' \
671 -e 's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p' \
673 test -s "$1.sq" ||
return
676 while read -r pick sha1 message
679 *" $sha1 "*) continue ;;
681 printf '%s\n' "$pick $sha1 $message"
682 while read -r squash action msg
686 printf '%s\n' "$action $squash $action! $msg"
691 done >"$1.rearranged" <"$1"
692 cat "$1.rearranged" >"$1"
693 rm -f "$1.sq" "$1.rearranged"
701 if left
=${1%...*} right
=${1#*...} &&
702 onto
=$
(git merge-base
--all ${left:-HEAD} ${right:-HEAD})
712 git rev-parse
--verify "$1^0"
719 OK_TO_SKIP_PRE_REBASE
=yes
724 is_standalone
"$@" || usage
726 comment_for_reflog
continue
728 test -d "$DOTEST" || die
"No interactive rebase running"
731 git rev-parse
--verify HEAD
>/dev
/null ||
732 die
"Cannot read HEAD"
733 git update-index
--ignore-submodules --refresh &&
734 git diff-files
--quiet --ignore-submodules ||
735 die
"Working tree is dirty"
737 # do we have anything to commit?
738 if git diff-index
--cached --quiet --ignore-submodules HEAD
--
740 : Nothing to commit
-- skip this
742 .
"$AUTHOR_SCRIPT" ||
743 die
"Cannot find the author identity"
747 amend
=$
(git rev-parse
--verify HEAD
)
748 test "$amend" = $
(cat "$AMEND") ||
750 You have uncommitted changes in your working tree. Please, commit them
751 first and then run 'git rebase --continue' again."
752 git
reset --soft HEAD^ ||
753 die
"Cannot rewind the HEAD"
755 do_with_author git commit
--no-verify -F "$MSG" -e ||
{
756 test -n "$amend" && git
reset --soft $amend
757 die
"Could not commit staged changes."
761 record_in_rewritten
"$(cat "$DOTEST"/stopped-sha)"
763 require_clean_work_tree
"rebase"
767 is_standalone
"$@" || usage
769 comment_for_reflog abort
772 test -d "$DOTEST" || die
"No interactive rebase running"
774 HEADNAME
=$
(cat "$DOTEST"/head-name
)
775 HEAD
=$
(cat "$DOTEST"/head)
778 git symbolic-ref HEAD
$HEADNAME
781 output git
reset --hard $HEAD &&
786 is_standalone
"$@" || usage
788 comment_for_reflog skip
791 test -d "$DOTEST" || die
"No interactive rebase running"
793 output git
reset --hard && do_rest
798 STRATEGY
="-s "$
(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
807 # we use merge anyway
832 ONTO
=$
(parse_onto
"$1") ||
833 die
"Does not point to a valid commit: $1"
837 test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
838 test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
840 die
"Interactive rebase already started"
842 git var GIT_COMMITTER_IDENT
>/dev
/null ||
843 die
"You need to set your committer info first"
845 if test -z "$REBASE_ROOT"
848 UPSTREAM
=$
(git rev-parse
--verify "$1") || die
"Invalid base"
849 test -z "$ONTO" && ONTO
=$UPSTREAM
855 die
"You must specify --onto when using --root"
857 run_pre_rebase_hook
"$UPSTREAM_ARG" "$@"
859 comment_for_reflog start
861 require_clean_work_tree
"rebase" "Please commit or stash them."
865 output git checkout
"$1" ||
866 die
"Could not checkout $1"
869 HEAD
=$
(git rev-parse
--verify HEAD
) || die
"No HEAD?"
870 mkdir
"$DOTEST" || die
"Could not create temporary $DOTEST"
872 : > "$DOTEST"/interactive || die
"Could not mark as interactive"
873 git symbolic-ref HEAD
> "$DOTEST"/head-name
2> /dev
/null ||
874 echo "detached HEAD" > "$DOTEST"/head-name
876 echo $HEAD > "$DOTEST"/head
877 case "$REBASE_ROOT" in
879 rm -f "$DOTEST"/rebase-root
;;
881 : >"$DOTEST"/rebase-root
;;
883 echo $ONTO > "$DOTEST"/onto
884 test -z "$STRATEGY" ||
echo "$STRATEGY" > "$DOTEST"/strategy
885 test t
= "$VERBOSE" && : > "$DOTEST"/verbose
886 if test t
= "$PRESERVE_MERGES"
888 if test -z "$REBASE_ROOT"
890 mkdir
"$REWRITTEN" &&
891 for c
in $
(git merge-base
--all $HEAD $UPSTREAM)
893 echo $ONTO > "$REWRITTEN"/$c ||
894 die
"Could not init rewritten commits"
897 mkdir
"$REWRITTEN" &&
898 echo $ONTO > "$REWRITTEN"/root ||
899 die
"Could not init rewritten commits"
901 # No cherry-pick because our first pass is to determine
902 # parents to rewrite and skipping dropped commits would
903 # prematurely end our probe
905 first_after_upstream
="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
907 MERGES_OPTION
="--no-merges --cherry-pick"
910 SHORTHEAD
=$
(git rev-parse
--short $HEAD)
911 SHORTONTO
=$
(git rev-parse
--short $ONTO)
912 if test -z "$REBASE_ROOT"
913 # this is now equivalent to ! -z "$UPSTREAM"
915 SHORTUPSTREAM
=$
(git rev-parse
--short $UPSTREAM)
916 REVISIONS
=$UPSTREAM...
$HEAD
917 SHORTREVISIONS
=$SHORTUPSTREAM..
$SHORTHEAD
919 REVISIONS
=$ONTO...
$HEAD
920 SHORTREVISIONS
=$SHORTHEAD
922 git rev-list
$MERGES_OPTION --pretty=oneline
--abbrev-commit \
923 --abbrev=7 --reverse --left-right --topo-order \
926 while read -r shortsha1 rest
928 if test t
!= "$PRESERVE_MERGES"
930 printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
932 sha1
=$
(git rev-parse
$shortsha1)
933 if test -z "$REBASE_ROOT"
936 for p
in $
(git rev-list
--parents -1 $sha1 | cut
-d' ' -s -f2-)
938 if test -f "$REWRITTEN"/$p -a \
( $p != $ONTO -o $sha1 = $first_after_upstream \
)
946 if test f
= "$preserve"
948 touch "$REWRITTEN"/$sha1
949 printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
954 # Watch for commits that been dropped by --cherry-pick
955 if test t
= "$PRESERVE_MERGES"
958 # Save all non-cherry-picked changes
959 git rev-list
$REVISIONS --left-right --cherry-pick | \
960 sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
961 # Now all commits and note which ones are missing in
962 # not-cherry-picks and hence being dropped
963 git rev-list
$REVISIONS |
966 if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
968 # Use -f2 because if rev-list is telling us this commit is
969 # not worthwhile, we don't want to track its multiple heads,
970 # just the history of its first-parent for others that will
971 # be rebasing on top of it
972 git rev-list
--parents -1 $rev | cut
-d' ' -s -f2 > "$DROPPED"/$rev
973 short
=$
(git rev-list
-1 --abbrev-commit --abbrev=7 $rev)
974 sane_grep
-v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
980 test -s "$TODO" ||
echo noop
>> "$TODO"
981 test -n "$AUTOSQUASH" && rearrange_squash
"$TODO"
982 cat >> "$TODO" << EOF
984 # Rebase $SHORTREVISIONS onto $SHORTONTO
987 # p, pick = use commit
988 # r, reword = use commit, but edit the commit message
989 # e, edit = use commit, but stop for amending
990 # s, squash = use commit, but meld into previous commit
991 # f, fixup = like "squash", but discard this commit's log message
992 # x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
994 # If you remove a line here THAT COMMIT WILL BE LOST.
995 # However, if you remove everything, the rebase will be aborted.
999 has_action
"$TODO" ||
1000 die_abort
"Nothing to do"
1002 cp "$TODO" "$TODO".backup
1003 git_editor
"$TODO" ||
1004 die_abort
"Could not execute editor"
1006 has_action
"$TODO" ||
1007 die_abort
"Nothing to do"
1009 test -d "$REWRITTEN" ||
test -n "$NEVER_FF" || skip_unnecessary_picks
1011 output git checkout
$ONTO || die_abort
"could not detach HEAD"
1012 git update-ref ORIG_HEAD
$HEAD