1 # This shell script fragment is sourced by git-rebase to implement its
2 # preserve-merges mode.
4 # Copyright (c) 2006 Johannes E. Schindelin
6 # The file containing rebase commands, comments, and empty lines.
7 # This file is created by "git rebase -i" then edited by the user. As
8 # the lines are processed, they are removed from the front of this
9 # file and written to the tail of $done.
10 todo="$state_dir"/git-rebase-todo
12 # The rebase command lines that have already been processed. A line
13 # is moved here when it is first handled, before any associated user
15 done="$state_dir"/done
17 # The commit message that is planned to be used for any changes that
18 # need to be committed following a user interaction.
19 msg="$state_dir"/message
21 # The file into which is accumulated the suggested commit message for
22 # squash/fixup commands. When the first of a series of squash/fixups
23 # is seen, the file is created and the commit message from the
24 # previous commit and from the first squash/fixup commit are written
25 # to it. The commit message for each subsequent squash/fixup commit
26 # is appended to the file as it is processed.
28 # The first line of the file is of the form
29 # # This is a combination of $count commits.
30 # where $count is the number of commits whose messages have been
31 # written to the file so far (including the initial "pick" commit).
32 # Each time that a commit message is processed, this line is read and
33 # updated. It is deleted just before the combined commit is made.
34 squash_msg="$state_dir"/message-squash
36 # If the current series of squash/fixups has not yet included a squash
37 # command, then this file exists and holds the commit message of the
38 # original "pick" commit. (If the series ends without a "squash"
39 # command, then this can be used as the commit message of the combined
40 # commit without opening the editor.)
41 fixup_msg="$state_dir"/message-fixup
43 # $rewritten is the name of a directory containing files for each
44 # commit that is reachable by at least one merge base of $head and
45 # $upstream. They are not necessarily rewritten, but their children
46 # might be. This ensures that commits on merged, but otherwise
47 # unrelated side branches are left alone. (Think "X" in the man page's
49 rewritten="$state_dir"/rewritten
51 dropped="$state_dir"/dropped
54 msgnum="$state_dir"/msgnum
56 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
57 # GIT_AUTHOR_DATE that will be used for the commit that is currently
59 author_script="$state_dir"/author-script
61 # When an "edit" rebase command is being processed, the SHA1 of the
62 # commit to be edited is recorded in this file. When "git rebase
63 # --continue" is executed, if there are any staged changes then they
64 # will be amended to the HEAD commit, but only provided the HEAD
65 # commit is still the commit to be edited. When any other rebase
66 # command is processed, this file is deleted.
67 amend="$state_dir"/amend
69 # For the post-rewrite hook, we make a list of rewritten commits and
70 # their new sha1s. The rewritten-pending list keeps the sha1s of
71 # commits that have been processed, but not committed yet,
72 # e.g. because they are waiting for a 'squash' command.
73 rewritten_list="$state_dir"/rewritten-list
74 rewritten_pending="$state_dir"/rewritten-pending
76 # Work around Git for Windows' Bash whose "read" does not strip CRLF
77 # and leaves CR at the end instead.
81 $(gettext 'Resolve all conflicts manually, mark them as resolved with
82 "git add/rm <conflicted_files>", then run "git rebase --continue".
83 You can instead skip this commit: run "git rebase --skip".
84 To abort and get back to the state before "git rebase", run "git rebase --abort".')
87 write_basic_state () {
88 echo "$head_name" > "$state_dir"/head-name &&
89 echo "$onto" > "$state_dir"/onto &&
90 echo "$orig_head" > "$state_dir"/orig-head &&
91 test t = "$GIT_QUIET" && : > "$state_dir"/quiet
92 test t = "$verbose" && : > "$state_dir"/verbose
93 test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
94 test -n "$strategy_opts" && echo "$strategy_opts" > \
95 "$state_dir"/strategy_opts
96 test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
97 "$state_dir"/allow_rerere_autoupdate
98 test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
99 test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
100 test -n "$reschedule_failed_exec" && : > "$state_dir"/reschedule-failed-exec
104 if test -f "$state_dir/autostash"
106 stash_sha1=$(cat "$state_dir/autostash")
107 if git stash apply $stash_sha1 >/dev/null 2>&1
109 echo "$(gettext 'Applied autostash.')" >&2
111 git stash store -m "autostash" -q $stash_sha1 ||
112 die "$(eval_gettext "Cannot store \$stash_sha1")"
113 gettext 'Applying autostash resulted in conflicts.
114 Your changes are safe in the stash.
115 You can run "git stash pop" or "git stash drop" at any time.
126 test $status != 0 && printf "%s\n" "$output"
135 strategy_args=${strategy:+--strategy=$strategy}
136 test -n "$strategy_opts" &&
138 for strategy_opt in '"$strategy_opts"'
140 strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
144 GIT_CHERRY_PICK_HELP="$resolvemsg"
145 export GIT_CHERRY_PICK_HELP
147 comment_char=$(git config --get core.commentchar 2>/dev/null)
148 case "$comment_char" in
155 comment_char=$(echo "$comment_char" | cut -c1)
160 printf '%s\n' "$*" >&2
163 # Output the commit message for the specified commit.
165 git cat-file commit "$1" | sed "1,/^$/d"
168 orig_reflog_action="$GIT_REFLOG_ACTION"
170 comment_for_reflog () {
171 case "$orig_reflog_action" in
173 GIT_REFLOG_ACTION="rebase -i ($1)"
174 export GIT_REFLOG_ACTION
180 mark_action_done () {
181 sed -e 1q < "$todo" >> "$done"
182 sed -e 1d < "$todo" >> "$todo".new
183 mv -f "$todo".new "$todo"
184 new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
185 echo $new_count >"$msgnum"
186 total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
188 if test "$last_count" != "$new_count"
190 last_count=$new_count
191 eval_gettext "Rebasing (\$new_count/\$total)"; printf "\r"
192 test -z "$verbose" || echo
196 append_todo_help () {
199 p, pick <commit> = use commit
200 r, reword <commit> = use commit, but edit the commit message
201 e, edit <commit> = use commit, but stop for amending
202 s, squash <commit> = use commit, but meld into previous commit
203 f, fixup <commit> = like \"squash\", but discard this commit's log message
204 x, exec <commit> = run command (the rest of the line) using shell
205 d, drop <commit> = remove commit
206 l, label <label> = label current HEAD with a name
207 t, reset <label> = reset HEAD to a label
208 m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
209 . create a merge commit using the original merge commit's
210 . message (or the oneline, if no original merge commit was
211 . specified). Use -c <commit> to reword the commit message.
213 These lines can be re-ordered; they are executed from top to bottom.
214 " | git stripspace --comment-lines >>"$todo"
216 if test $(get_missing_commit_check_level) = error
219 Do not remove any line. Use 'drop' explicitly to remove a commit.
220 " | git stripspace --comment-lines >>"$todo"
223 If you remove a line here THAT COMMIT WILL BE LOST.
224 " | git stripspace --comment-lines >>"$todo"
229 sha1_and_parents="$(git rev-list --parents -1 "$1")"
230 case "$sha1_and_parents" in
232 git diff --cc $sha1_and_parents
235 git diff-tree -p "$1^!"
240 esac > "$state_dir"/patch
242 commit_message "$1" > "$msg"
243 test -f "$author_script" ||
244 get_author_ident_from_commit "$1" > "$author_script"
248 echo "$1" > "$state_dir"/stopped-sha
249 git update-ref REBASE_HEAD "$1"
255 echo "$1" > "$state_dir"/stopped-sha
256 git update-ref REBASE_HEAD "$1"
258 git rev-parse --verify HEAD > "$amend"
259 gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
260 warn "$(eval_gettext "\
261 You can amend the commit now, with
263 git commit --amend \$gpg_sign_opt_quoted
265 Once you are satisfied with your changes, run
267 git rebase --continue")"
279 test -n "$(git stripspace --strip-comments <"$1")"
283 tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null) || {
285 die "$(eval_gettext "\$sha1: not a commit that can be picked")"
287 ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) ||
288 ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
289 test "$tree" = "$ptree"
294 git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
297 # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
298 # GIT_AUTHOR_DATE exported from the current environment.
301 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
306 git_sequence_editor () {
307 if test -z "$GIT_SEQUENCE_EDITOR"
309 GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"
310 if [ -z "$GIT_SEQUENCE_EDITOR" ]
312 GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?
316 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
322 case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
323 case "$force_rebase" in '') ;; ?*) ff= ;; esac
324 output git rev-parse --verify $sha1 || die "$(eval_gettext "Invalid commit name: \$sha1")"
326 if is_empty_commit "$sha1"
328 empty_args="--allow-empty"
331 pick_one_preserving_merges "$@"
334 pick_one_preserving_merges () {
345 sha1=$(git rev-parse $sha1)
347 if test -f "$state_dir"/current-commit && test "$fast_forward" = t
349 while read current_commit
351 git rev-parse HEAD > "$rewritten"/$current_commit
352 done <"$state_dir"/current-commit
353 rm "$state_dir"/current-commit ||
354 die "$(gettext "Cannot write current commit's replacement sha1")"
357 echo $sha1 >> "$state_dir"/current-commit
359 # rewrite parents; if none were rewritten, we can fast-forward.
361 pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
362 if test "$pend" = " "
366 while [ "$pend" != "" ]
368 p=$(expr "$pend" : ' \([^ ]*\)')
371 if test -f "$rewritten"/$p
373 new_p=$(cat "$rewritten"/$p)
375 # If the todo reordered commits, and our parent is marked for
376 # rewriting, but hasn't been gotten to yet, assume the user meant to
377 # drop it on top of the current HEAD
380 new_p=$(git rev-parse HEAD)
383 test $p != $new_p && fast_forward=f
384 case "$new_parents" in
386 ;; # do nothing; that parent is already there
388 new_parents="$new_parents $new_p"
392 if test -f "$dropped"/$p
395 replacement="$(cat "$dropped"/$p)"
396 test -z "$replacement" && replacement=root
397 pend=" $replacement$pend"
399 new_parents="$new_parents $p"
403 case $fast_forward in
405 output warn "$(eval_gettext "Fast-forward to \$sha1")"
406 output git reset --hard $sha1 ||
407 die "$(eval_gettext "Cannot fast-forward to \$sha1")"
410 first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
414 # detach HEAD to current parent
415 output git checkout $first_parent 2> /dev/null ||
416 die "$(eval_gettext "Cannot move HEAD to \$first_parent")"
419 case "$new_parents" in
421 test "a$1" = a-n && die "$(eval_gettext "Refusing to squash a merge: \$sha1")"
424 author_script_content=$(get_author_ident_from_commit $sha1)
425 eval "$author_script_content"
426 msg_content="$(commit_message $sha1)"
427 # No point in merging the first parent, that's HEAD
428 new_parents=${new_parents# $first_parent}
429 merge_args="--no-log --no-ff"
430 if ! do_with_author output eval \
431 git merge ${gpg_sign_opt:+$(git rev-parse \
432 --sq-quote "$gpg_sign_opt")} \
433 $allow_rerere_autoupdate "$merge_args" \
435 -m "$(git rev-parse --sq-quote "$msg_content")" \
438 printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
439 die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")"
441 echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
444 output eval git cherry-pick $allow_rerere_autoupdate \
445 $allow_empty_message \
446 ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
447 "$strategy_args" "$@" ||
448 die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")"
455 this_nth_commit_message () {
457 eval_gettext "This is the commit message #\${n}:"
460 skip_nth_commit_message () {
462 eval_gettext "The commit message #\${n} will be skipped:"
465 update_squash_messages () {
466 if test -f "$squash_msg"; then
467 mv "$squash_msg" "$squash_msg".bak || exit
469 -e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
470 -e "q" < "$squash_msg".bak)+1))
472 printf '%s\n' "$comment_char $(eval_ngettext \
473 "This is a combination of \$count commit." \
474 "This is a combination of \$count commits." \
476 sed -e 1d -e '2,/^./{
478 }' <"$squash_msg".bak
481 commit_message HEAD >"$fixup_msg" ||
482 die "$(eval_gettext "Cannot write \$fixup_msg")"
485 printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
486 printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")"
495 printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
501 printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
503 # Change the space after the comment character to TAB:
504 commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
509 peek_next_command () {
510 git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
513 # A squash/fixup has failed. Prepare the long version of the squash
514 # commit message, then die_with_patch. This code path requires the
515 # user to edit the combined commit message for all commits that have
516 # been squashed/fixedup so far. So also erase the old squash
517 # messages, effectively causing the combined commit to be used as the
518 # new basis for any further squash/fixups. Args: sha1 rest
519 die_failed_squash() {
522 mv "$squash_msg" "$msg" || exit
524 cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
526 warn "$(eval_gettext "Could not apply \$sha1... \$rest")"
527 die_with_patch $sha1 ""
530 flush_rewritten_pending() {
531 test -s "$rewritten_pending" || return
532 newsha1="$(git rev-parse HEAD^0)"
533 sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
534 rm -f "$rewritten_pending"
537 record_in_rewritten() {
538 oldsha1="$(git rev-parse $1)"
539 echo "$oldsha1" >> "$rewritten_pending"
541 case "$(peek_next_command)" in
545 flush_rewritten_pending
553 if test "$(git rev-parse HEAD)" = "$squash_onto"
555 # Set the correct commit message and author info on the
556 # sentinel root before cherry-picking the original changes
557 # without committing (-n). Finally, update the sentinel again
558 # to include these changes. If the cherry-pick results in a
559 # conflict, this means our behaviour is similar to a standard
560 # failed cherry-pick during rebase, with a dirty index to
561 # resolve before manually running git commit --amend then git
563 git commit --allow-empty --allow-empty-message --amend \
564 --no-post-rewrite -n -q -C $sha1 $signoff &&
566 git commit --allow-empty --allow-empty-message \
567 --amend --no-post-rewrite -n -q -C $sha1 $signoff \
568 ${gpg_sign_opt:+"$gpg_sign_opt"} ||
569 die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
572 die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
577 rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
578 read -r command sha1 rest < "$todo"
580 "$comment_char"*|''|noop|drop|d)
584 # Work around CR left by "read" (e.g. with Git for Windows' Bash).
588 comment_for_reflog pick
591 do_pick $sha1 "$rest"
592 record_in_rewritten $sha1
595 comment_for_reflog reword
598 do_pick $sha1 "$rest"
599 git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} \
600 $allow_empty_message || {
601 warn "$(eval_gettext "\
602 Could not amend commit after successfully picking \$sha1... \$rest
603 This is most likely due to an empty commit message, or the pre-commit hook
604 failed. If the pre-commit hook failed, you may need to resolve the issue before
605 you are able to reword the commit.")"
606 exit_with_patch $sha1 1
608 record_in_rewritten $sha1
611 comment_for_reflog edit
614 do_pick $sha1 "$rest"
615 sha1_abbrev=$(git rev-parse --short $sha1)
616 warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")"
617 exit_with_patch $sha1 0
628 comment_for_reflog $squash_style
630 test -f "$done" && has_action "$done" ||
631 die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")"
634 update_squash_messages $squash_style $sha1
635 author_script_content=$(get_author_ident_from_commit HEAD)
636 echo "$author_script_content" > "$author_script"
637 eval "$author_script_content"
638 if ! pick_one -n $sha1
640 git rev-parse --verify HEAD >"$amend"
641 die_failed_squash $sha1 "$rest"
643 case "$(peek_next_command)" in
645 # This is an intermediate commit; its message will only be
646 # used in case of trouble. So use the long version:
647 do_with_author output git commit --amend --no-verify -F "$squash_msg" \
648 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
649 die_failed_squash $sha1 "$rest"
652 # This is the final command of this squash/fixup group
653 if test -f "$fixup_msg"
655 do_with_author git commit --amend --no-verify -F "$fixup_msg" \
656 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
657 die_failed_squash $sha1 "$rest"
659 cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
660 rm -f "$GIT_DIR"/MERGE_MSG
661 do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
662 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
663 die_failed_squash $sha1 "$rest"
665 rm -f "$squash_msg" "$fixup_msg"
668 record_in_rewritten $sha1
671 read -r command rest < "$todo"
673 eval_gettextln "Executing: \$rest"
674 "${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
676 # Run in subshell because require_clean_work_tree can die.
678 (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
679 if test "$status" -ne 0
681 warn "$(eval_gettext "Execution failed: \$rest")"
683 warn "$(gettext "and made changes to the index and/or the working tree")"
686 You can fix the problem, and then run
688 git rebase --continue")"
690 if test $status -eq 127 # command not found
695 elif test "$dirty" = t
697 # TRANSLATORS: after these lines is a command to be issued by the user
698 warn "$(eval_gettext "\
699 Execution succeeded: \$rest
700 but left changes to the index and/or the working tree
701 Commit or stash your changes, and then run
703 git rebase --continue")"
709 warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")"
710 fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")"
711 if git rev-parse --verify -q "$sha1" >/dev/null
713 die_with_patch $sha1 "$fixtodo"
719 test -s "$todo" && return
721 comment_for_reflog finish &&
722 newhead=$(git rev-parse HEAD) &&
725 message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
726 git update-ref -m "$message" $head_name $newhead $orig_head &&
728 -m "$GIT_REFLOG_ACTION: returning to $head_name" \
732 test ! -f "$state_dir"/verbose ||
733 git diff-tree --stat $orig_head..HEAD
736 test -s "$rewritten_list" &&
737 git notes copy --for-rewrite=rebase < "$rewritten_list" ||
738 true # we don't care if this copying failed
740 hook="$(git rev-parse --git-path hooks/post-rewrite)"
741 if test -x "$hook" && test -s "$rewritten_list"; then
742 "$hook" rebase < "$rewritten_list"
743 true # we don't care if this hook failed
745 warn "$(eval_gettext "Successfully rebased and updated \$head_name.")"
747 return 1 # not failure; just to break the do_rest loop
750 # can only return 0, when the infinite loop breaks
759 git rebase--interactive --expand-ids
762 collapse_todo_ids() {
763 git rebase--interactive --shorten-ids
766 # Switch to the branch in $into and notify it in the reflog
768 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
769 output git checkout $onto || die_abort "$(gettext "could not detach HEAD")"
770 git update-ref ORIG_HEAD $orig_head
773 get_missing_commit_check_level () {
774 check_level=$(git config --get rebase.missingCommitsCheck)
775 check_level=${check_level:-ignore}
776 # Don't be case sensitive
777 printf '%s' "$check_level" | tr 'A-Z' 'a-z'
780 # Initiate an action. If the cannot be any
781 # further action it may exec a command
782 # or exit and not return.
784 # TODO: Consider a cleaner return model so it
785 # never exits and always return 0 if process
788 # Parameter 1 is the action to initiate.
790 # Returns 0 if the action was able to complete
791 # and if 1 if further processing is required.
795 # do we have anything to commit?
796 if git diff-index --cached --quiet HEAD --
798 # Nothing to commit -- skip this commit
800 test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
801 rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
802 die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
804 if ! test -f "$author_script"
806 gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
807 die "$(eval_gettext "\
808 You have staged changes in your working tree.
809 If these changes are meant to be
810 squashed into the previous commit, run:
812 git commit --amend \$gpg_sign_opt_quoted
814 If they are meant to go into a new commit, run:
816 git commit \$gpg_sign_opt_quoted
818 In both cases, once you're done, continue with:
820 git rebase --continue
823 . "$author_script" ||
824 die "$(gettext "Error trying to find the author identity to amend commit")"
827 current_head=$(git rev-parse --verify HEAD)
828 test "$current_head" = $(cat "$amend") ||
830 You have uncommitted changes in your working tree. Please commit them
831 first and then run 'git rebase --continue' again.")"
832 do_with_author git commit --amend --no-verify -F "$msg" -e \
833 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
834 die "$(gettext "Could not commit staged changes.")"
836 do_with_author git commit --no-verify -F "$msg" -e \
837 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
838 die "$(gettext "Could not commit staged changes.")"
842 if test -r "$state_dir"/stopped-sha
844 record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
847 require_clean_work_tree "rebase"
857 git stripspace --strip-comments <"$todo" >"$todo".new
858 mv -f "$todo".new "$todo"
862 You are editing the todo file of an ongoing interactive rebase.
863 To continue rebase after editing, run:
864 git rebase --continue
866 " | git stripspace --comment-lines >>"$todo"
868 git_sequence_editor "$todo" ||
869 die "$(gettext "Could not execute editor")"
875 exec git show REBASE_HEAD --
883 setup_reflog_action () {
884 comment_for_reflog start
886 if test ! -z "$switch_to"
888 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
889 output git checkout "$switch_to" -- ||
890 die "$(eval_gettext "Could not checkout \$switch_to")"
892 comment_for_reflog start
896 init_basic_state () {
897 orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
898 mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
899 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
901 : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
905 init_revisions_and_shortrevisions () {
906 shorthead=$(git rev-parse --short $orig_head)
907 shortonto=$(git rev-parse --short $onto)
908 if test -z "$rebase_root"
909 # this is now equivalent to ! -z "$upstream"
911 shortupstream=$(git rev-parse --short $upstream)
912 revisions=$upstream...$orig_head
913 shortrevisions=$shortupstream..$shorthead
915 revisions=$onto...$orig_head
916 shortrevisions=$shorthead
917 test -z "$squash_onto" ||
918 echo "$squash_onto" >"$state_dir"/squash-onto
923 test -s "$todo" || echo noop >> "$todo"
924 test -z "$autosquash" || git rebase--interactive --rearrange-squash || exit
925 test -n "$cmd" && git rebase--interactive --add-exec-commands --cmd "$cmd"
927 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
928 todocount=${todocount##* }
932 $comment_char $(eval_ngettext \
933 "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
934 "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
939 However, if you remove everything, the rebase will be aborted.
941 " | git stripspace --comment-lines >>"$todo"
943 if test -z "$keep_empty"
945 printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
949 has_action "$todo" ||
952 cp "$todo" "$todo".backup
954 git_sequence_editor "$todo" ||
955 die_abort "$(gettext "Could not execute editor")"
957 has_action "$todo" ||
960 git rebase--interactive --check-todo-list || {
971 git_rebase__preserve_merges () {
972 initiate_action "$action"
974 if test $ret = 0; then
981 if test -z "$rebase_root"
983 mkdir "$rewritten" &&
984 for c in $(git merge-base --all $orig_head $upstream)
986 echo $onto > "$rewritten"/$c ||
987 die "$(gettext "Could not init rewritten commits")"
990 mkdir "$rewritten" &&
991 echo $onto > "$rewritten"/root ||
992 die "$(gettext "Could not init rewritten commits")"
995 init_revisions_and_shortrevisions
997 format=$(git config --get rebase.instructionFormat)
998 # the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
999 git rev-list --format="%m%H ${format:-%s}" \
1000 --reverse --left-right --topo-order \
1001 $revisions ${restrict_revision+^$restrict_revision} | \
1003 while read -r sha1 rest
1005 if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
1007 comment_out="$comment_char "
1012 if test -z "$rebase_root"
1015 for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
1017 if test -f "$rewritten"/$p
1025 if test f = "$preserve"
1027 touch "$rewritten"/$sha1
1028 printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
1032 # Watch for commits that been dropped by --cherry-pick
1034 # Save all non-cherry-picked changes
1035 git rev-list $revisions --left-right --cherry-pick | \
1036 sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
1037 # Now all commits and note which ones are missing in
1038 # not-cherry-picks and hence being dropped
1039 git rev-list $revisions |
1042 if test -f "$rewritten"/$rev &&
1043 ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
1045 # Use -f2 because if rev-list is telling us this commit is
1046 # not worthwhile, we don't want to track its multiple heads,
1047 # just the history of its first-parent for others that will
1048 # be rebasing on top of it
1049 git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
1050 sha1=$(git rev-list -1 $rev)
1051 sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1052 rm "$rewritten"/$rev