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 # Put the last action marked done at the beginning of the todo list
197 # again. If there has not been an action marked done yet, leave the list of
198 # items on the todo list unchanged.
199 reschedule_last_action
() {
200 tail -n 1 "$done" |
cat - "$todo" >"$todo".new
201 sed -e \
$d <"$done" >"$done".new
202 mv -f "$todo".new
"$todo"
203 mv -f "$done".new
"$done"
206 append_todo_help
() {
209 p, pick <commit> = use commit
210 r, reword <commit> = use commit, but edit the commit message
211 e, edit <commit> = use commit, but stop for amending
212 s, squash <commit> = use commit, but meld into previous commit
213 f, fixup <commit> = like \"squash\", but discard this commit's log message
214 x, exec <commit> = run command (the rest of the line) using shell
215 d, drop <commit> = remove commit
216 l, label <label> = label current HEAD with a name
217 t, reset <label> = reset HEAD to a label
218 m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
219 . create a merge commit using the original merge commit's
220 . message (or the oneline, if no original merge commit was
221 . specified). Use -c <commit> to reword the commit message.
223 These lines can be re-ordered; they are executed from top to bottom.
224 " | git stripspace
--comment-lines >>"$todo"
226 if test $
(get_missing_commit_check_level
) = error
229 Do not remove any line. Use 'drop' explicitly to remove a commit.
230 " | git stripspace
--comment-lines >>"$todo"
233 If you remove a line here THAT COMMIT WILL BE LOST.
234 " | git stripspace
--comment-lines >>"$todo"
239 sha1_and_parents
="$(git rev-list --parents -1 "$1")"
240 case "$sha1_and_parents" in
242 git
diff --cc $sha1_and_parents
245 git diff-tree
-p "$1^!"
250 esac > "$state_dir"/patch
252 commit_message
"$1" > "$msg"
253 test -f "$author_script" ||
254 get_author_ident_from_commit
"$1" > "$author_script"
258 echo "$1" > "$state_dir"/stopped-sha
259 git update-ref REBASE_HEAD
"$1"
265 echo "$1" > "$state_dir"/stopped-sha
266 git update-ref REBASE_HEAD
"$1"
268 git rev-parse
--verify HEAD
> "$amend"
269 gpg_sign_opt_quoted
=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
270 warn
"$(eval_gettext "\
271 You can amend the commit now
, with
273 git commit
--amend \
$gpg_sign_opt_quoted
275 Once you are satisfied with your changes
, run
277 git rebase
--continue")"
289 test -n "$(git stripspace --strip-comments <"$1")"
293 tree
=$
(git rev-parse
-q --verify "$1"^
{tree
} 2>/dev
/null
) ||
{
295 die
"$(eval_gettext "\
$sha1: not a commit that can be picked
")"
297 ptree
=$
(git rev-parse
-q --verify "$1"^^
{tree
} 2>/dev
/null
) ||
298 ptree
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
299 test "$tree" = "$ptree"
304 git rev-parse
--verify --quiet "$1"^
2 >/dev
/null
2>&1
307 # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
308 # GIT_AUTHOR_DATE exported from the current environment.
311 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
316 git_sequence_editor
() {
317 if test -z "$GIT_SEQUENCE_EDITOR"
319 GIT_SEQUENCE_EDITOR
="$(git config sequence.editor)"
320 if [ -z "$GIT_SEQUENCE_EDITOR" ]
322 GIT_SEQUENCE_EDITOR
="$(git var GIT_EDITOR)" ||
return $?
326 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
332 case "$1" in -n) sha1
=$2; ff
= ;; *) sha1
=$1 ;; esac
333 case "$force_rebase" in '') ;; ?
*) ff
= ;; esac
334 output git rev-parse
--verify $sha1 || die
"$(eval_gettext "Invalid commit name
: \
$sha1")"
336 if is_empty_commit
"$sha1"
338 empty_args
="--allow-empty"
341 pick_one_preserving_merges
"$@"
344 pick_one_preserving_merges
() {
355 sha1
=$
(git rev-parse
$sha1)
357 if test -f "$state_dir"/current-commit
&& test "$fast_forward" = t
359 while read current_commit
361 git rev-parse HEAD
> "$rewritten"/$current_commit
362 done <"$state_dir"/current-commit
363 rm "$state_dir"/current-commit ||
364 die
"$(gettext "Cannot
write current commit
's replacement sha1")"
367 echo $sha1 >> "$state_dir"/current-commit
369 # rewrite parents; if none were rewritten, we can fast-forward.
371 pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
372 if test "$pend" = " "
376 while [ "$pend" != "" ]
378 p=$(expr "$pend" : ' \
([^
]*\
)')
381 if test -f "$rewritten"/$p
383 new_p=$(cat "$rewritten"/$p)
385 # If the todo reordered commits, and our parent is marked for
386 # rewriting, but hasn't been gotten to yet
, assume the user meant to
387 # drop it on top of the current HEAD
390 new_p
=$
(git rev-parse HEAD
)
393 test $p != $new_p && fast_forward
=f
394 case "$new_parents" in
396 ;; # do nothing; that parent is already there
398 new_parents
="$new_parents $new_p"
402 if test -f "$dropped"/$p
405 replacement
="$(cat "$dropped"/$p)"
406 test -z "$replacement" && replacement
=root
407 pend
=" $replacement$pend"
409 new_parents
="$new_parents $p"
413 case $fast_forward in
415 output warn
"$(eval_gettext "Fast-forward to \
$sha1")"
416 output git
reset --hard $sha1 ||
417 die
"$(eval_gettext "Cannot fast-forward to \
$sha1")"
420 first_parent
=$
(expr "$new_parents" : ' \([^ ]*\)')
424 # detach HEAD to current parent
425 output git checkout
$first_parent 2> /dev
/null ||
426 die
"$(eval_gettext "Cannot move HEAD to \
$first_parent")"
429 case "$new_parents" in
431 test "a$1" = a-n
&& die
"$(eval_gettext "Refusing to squash a merge
: \
$sha1")"
434 author_script_content
=$
(get_author_ident_from_commit
$sha1)
435 eval "$author_script_content"
436 msg_content
="$(commit_message $sha1)"
437 # No point in merging the first parent, that's HEAD
438 new_parents
=${new_parents# $first_parent}
439 merge_args
="--no-log --no-ff"
440 if ! do_with_author output
eval \
441 git merge $
{gpg_sign_opt
:+$
(git rev-parse \
442 --sq-quote "$gpg_sign_opt")} \
443 $allow_rerere_autoupdate "$merge_args" \
445 -m "$(git rev-parse --sq-quote "$msg_content")" \
448 printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
449 die_with_patch
$sha1 "$(eval_gettext "Error redoing merge \
$sha1")"
451 echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
454 output
eval git cherry-pick
$allow_rerere_autoupdate \
455 $allow_empty_message \
456 ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
457 "$strategy_args" "$@" ||
458 die_with_patch
$sha1 "$(eval_gettext "Could not pick \
$sha1")"
465 this_nth_commit_message
() {
467 eval_gettext
"This is the commit message #\${n}:"
470 skip_nth_commit_message
() {
472 eval_gettext
"The commit message #\${n} will be skipped:"
475 update_squash_messages
() {
476 if test -f "$squash_msg"; then
477 mv "$squash_msg" "$squash_msg".bak ||
exit
479 -e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
480 -e "q" < "$squash_msg".bak
)+1))
482 printf '%s\n' "$comment_char $(eval_ngettext \
483 "This is a combination of \
$count commit.
" \
484 "This is a combination of \
$count commits.
" \
486 sed -e 1d
-e '2,/^./{
488 }' <"$squash_msg".bak
491 commit_message HEAD
>"$fixup_msg" ||
492 die
"$(eval_gettext "Cannot
write \
$fixup_msg")"
495 printf '%s\n' "$comment_char $(gettext "This is a combination of
2 commits.
")"
496 printf '%s\n' "$comment_char $(gettext "This is the
1st commit message
:")"
505 printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
511 printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
513 # Change the space after the comment character to TAB:
514 commit_message
$2 | git stripspace
--comment-lines |
sed -e 's/ / /'
519 peek_next_command
() {
520 git stripspace
--strip-comments <"$todo" |
sed -n -e 's/ .*//p' -e q
523 # A squash/fixup has failed. Prepare the long version of the squash
524 # commit message, then die_with_patch. This code path requires the
525 # user to edit the combined commit message for all commits that have
526 # been squashed/fixedup so far. So also erase the old squash
527 # messages, effectively causing the combined commit to be used as the
528 # new basis for any further squash/fixups. Args: sha1 rest
529 die_failed_squash
() {
532 mv "$squash_msg" "$msg" ||
exit
534 cp "$msg" "$GIT_DIR"/MERGE_MSG ||
exit
536 warn
"$(eval_gettext "Could not apply \
$sha1... \
$rest")"
537 die_with_patch
$sha1 ""
540 flush_rewritten_pending
() {
541 test -s "$rewritten_pending" ||
return
542 newsha1
="$(git rev-parse HEAD^0)"
543 sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
544 rm -f "$rewritten_pending"
547 record_in_rewritten
() {
548 oldsha1
="$(git rev-parse $1)"
549 echo "$oldsha1" >> "$rewritten_pending"
551 case "$(peek_next_command)" in
555 flush_rewritten_pending
563 if test "$(git rev-parse HEAD)" = "$squash_onto"
565 # Set the correct commit message and author info on the
566 # sentinel root before cherry-picking the original changes
567 # without committing (-n). Finally, update the sentinel again
568 # to include these changes. If the cherry-pick results in a
569 # conflict, this means our behaviour is similar to a standard
570 # failed cherry-pick during rebase, with a dirty index to
571 # resolve before manually running git commit --amend then git
573 git commit
--allow-empty --allow-empty-message --amend \
574 --no-post-rewrite -n -q -C $sha1 $signoff &&
576 git commit
--allow-empty --allow-empty-message \
577 --amend --no-post-rewrite -n -q -C $sha1 $signoff \
578 ${gpg_sign_opt:+"$gpg_sign_opt"} ||
579 die_with_patch
$sha1 "$(eval_gettext "Could not apply \
$sha1... \
$rest")"
582 die_with_patch
$sha1 "$(eval_gettext "Could not apply \
$sha1... \
$rest")"
587 rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha ||
exit
588 read -r command sha1 rest
< "$todo"
590 "$comment_char"*|
''|noop|drop|d
)
594 # Work around CR left by "read" (e.g. with Git for Windows' Bash).
598 comment_for_reflog pick
601 do_pick
$sha1 "$rest"
602 record_in_rewritten
$sha1
605 comment_for_reflog reword
608 do_pick
$sha1 "$rest"
609 git commit
--amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} \
610 $allow_empty_message ||
{
611 warn
"$(eval_gettext "\
612 Could not amend commit after successfully picking \
$sha1... \
$rest
613 This is most likely due to an empty commit message
, or the pre-commit hook
614 failed. If the pre-commit hook failed
, you may need to resolve the issue before
615 you are able to reword the commit.
")"
616 exit_with_patch
$sha1 1
618 record_in_rewritten
$sha1
621 comment_for_reflog edit
624 do_pick
$sha1 "$rest"
625 sha1_abbrev
=$
(git rev-parse
--short $sha1)
626 warn
"$(eval_gettext "Stopped
at \
$sha1_abbrev... \
$rest")"
627 exit_with_patch
$sha1 0
638 comment_for_reflog
$squash_style
640 test -f "$done" && has_action
"$done" ||
641 die
"$(eval_gettext "Cannot
'\$squash_style' without a previous commit
")"
644 update_squash_messages
$squash_style $sha1
645 author_script_content
=$
(get_author_ident_from_commit HEAD
)
646 echo "$author_script_content" > "$author_script"
647 eval "$author_script_content"
648 if ! pick_one
-n $sha1
650 git rev-parse
--verify HEAD
>"$amend"
651 die_failed_squash
$sha1 "$rest"
653 case "$(peek_next_command)" in
655 # This is an intermediate commit; its message will only be
656 # used in case of trouble. So use the long version:
657 do_with_author output git commit
--amend --no-verify -F "$squash_msg" \
658 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
659 die_failed_squash
$sha1 "$rest"
662 # This is the final command of this squash/fixup group
663 if test -f "$fixup_msg"
665 do_with_author git commit
--amend --no-verify -F "$fixup_msg" \
666 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
667 die_failed_squash
$sha1 "$rest"
669 cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG ||
exit
670 rm -f "$GIT_DIR"/MERGE_MSG
671 do_with_author git commit
--amend --no-verify -F "$GIT_DIR"/SQUASH_MSG
-e \
672 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
673 die_failed_squash
$sha1 "$rest"
675 rm -f "$squash_msg" "$fixup_msg"
678 record_in_rewritten
$sha1
681 read -r command rest
< "$todo"
683 eval_gettextln
"Executing: \$rest"
684 "${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
686 # Run in subshell because require_clean_work_tree can die.
688 (require_clean_work_tree
"rebase" 2>/dev
/null
) || dirty
=t
689 if test "$status" -ne 0
691 warn
"$(eval_gettext "Execution failed
: \
$rest")"
693 warn
"$(gettext "and made changes to the index and
/or the working tree
")"
696 You can fix the problem
, and
then run
698 git rebase
--continue")"
700 if test $status -eq 127 # command not found
705 elif test "$dirty" = t
707 # TRANSLATORS: after these lines is a command to be issued by the user
708 warn
"$(eval_gettext "\
709 Execution succeeded
: \
$rest
710 but left changes to the index and
/or the working tree
711 Commit or stash your changes
, and
then run
713 git rebase
--continue")"
719 warn
"$(eval_gettext "Unknown
command: \
$command \
$sha1 \
$rest")"
720 fixtodo
="$(gettext "Please fix this using
'git rebase --edit-todo'.
")"
721 if git rev-parse
--verify -q "$sha1" >/dev
/null
723 die_with_patch
$sha1 "$fixtodo"
729 test -s "$todo" && return
731 comment_for_reflog finish
&&
732 newhead
=$
(git rev-parse HEAD
) &&
735 message
="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
736 git update-ref
-m "$message" $head_name $newhead $orig_head &&
738 -m "$GIT_REFLOG_ACTION: returning to $head_name" \
742 test ! -f "$state_dir"/verbose ||
743 git diff-tree
--stat $orig_head..HEAD
746 test -s "$rewritten_list" &&
747 git notes copy
--for-rewrite=rebase
< "$rewritten_list" ||
748 true
# we don't care if this copying failed
750 hook
="$(git rev-parse --git-path hooks/post-rewrite)"
751 if test -x "$hook" && test -s "$rewritten_list"; then
752 "$hook" rebase
< "$rewritten_list"
753 true
# we don't care if this hook failed
755 warn
"$(eval_gettext "Successfully rebased and updated \
$head_name.
")"
757 return 1 # not failure; just to break the do_rest loop
760 # can only return 0, when the infinite loop breaks
769 git rebase--interactive
--expand-ids
772 collapse_todo_ids
() {
773 git rebase--interactive
--shorten-ids
776 # Switch to the branch in $into and notify it in the reflog
778 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION: checkout $onto_name"
779 output git checkout
$onto || die_abort
"$(gettext "could not detach HEAD
")"
780 git update-ref ORIG_HEAD
$orig_head
783 get_missing_commit_check_level
() {
784 check_level
=$
(git config
--get rebase.missingCommitsCheck
)
785 check_level
=${check_level:-ignore}
786 # Don't be case sensitive
787 printf '%s' "$check_level" |
tr 'A-Z' 'a-z'
790 # Initiate an action. If the cannot be any
791 # further action it may exec a command
792 # or exit and not return.
794 # TODO: Consider a cleaner return model so it
795 # never exits and always return 0 if process
798 # Parameter 1 is the action to initiate.
800 # Returns 0 if the action was able to complete
801 # and if 1 if further processing is required.
805 # do we have anything to commit?
806 if git diff-index
--cached --quiet HEAD
--
808 # Nothing to commit -- skip this commit
810 test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
811 rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
812 die
"$(gettext "Could not remove CHERRY_PICK_HEAD
")"
814 if ! test -f "$author_script"
816 gpg_sign_opt_quoted
=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
817 die
"$(eval_gettext "\
818 You have staged changes
in your working tree.
819 If these changes are meant to be
820 squashed into the previous commit
, run
:
822 git commit
--amend \
$gpg_sign_opt_quoted
824 If they are meant to go into a new commit
, run
:
826 git commit \
$gpg_sign_opt_quoted
828 In both cases
, once you
're done, continue with:
830 git rebase --continue
833 . "$author_script" ||
834 die "$(gettext "Error trying to find the author identity to amend commit")"
837 current_head=$(git rev-parse --verify HEAD)
838 test "$current_head" = $(cat "$amend") ||
840 You have uncommitted changes in your working tree. Please commit them
841 first and then run 'git rebase
--continue' again.")"
842 do_with_author git commit --amend --no-verify -F "$msg" -e \
843 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
844 die "$(gettext "Could not commit staged changes.")"
846 do_with_author git commit --no-verify -F "$msg" -e \
847 ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
848 die "$(gettext "Could not commit staged changes.")"
852 if test -r "$state_dir"/stopped-sha
854 record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
857 require_clean_work_tree "rebase"
867 git stripspace --strip-comments <"$todo" >"$todo".new
868 mv -f "$todo".new "$todo"
872 You are editing the todo file of an ongoing interactive rebase.
873 To continue rebase after editing, run:
874 git rebase --continue
876 " | git stripspace --comment-lines >>"$todo"
878 git_sequence_editor "$todo" ||
879 die "$(gettext "Could not execute editor")"
885 exec git show REBASE_HEAD --
893 setup_reflog_action () {
894 comment_for_reflog start
896 if test ! -z "$switch_to"
898 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
899 output git checkout "$switch_to" -- ||
900 die "$(eval_gettext "Could not checkout \$switch_to")"
902 comment_for_reflog start
906 init_basic_state () {
907 orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
908 mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
909 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
911 : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
915 init_revisions_and_shortrevisions () {
916 shorthead=$(git rev-parse --short $orig_head)
917 shortonto=$(git rev-parse --short $onto)
918 if test -z "$rebase_root"
919 # this is now equivalent to ! -z "$upstream"
921 shortupstream=$(git rev-parse --short $upstream)
922 revisions=$upstream...$orig_head
923 shortrevisions=$shortupstream..$shorthead
925 revisions=$onto...$orig_head
926 shortrevisions=$shorthead
927 test -z "$squash_onto" ||
928 echo "$squash_onto" >"$state_dir"/squash-onto
933 test -s "$todo" || echo noop >> "$todo"
934 test -z "$autosquash" || git rebase--interactive --rearrange-squash || exit
935 test -n "$cmd" && git rebase--interactive --add-exec-commands --cmd "$cmd"
937 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
938 todocount=${todocount##* }
942 $comment_char $(eval_ngettext \
943 "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
944 "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
949 However, if you remove everything, the rebase will be aborted.
951 " | git stripspace --comment-lines >>"$todo"
953 if test -z "$keep_empty"
955 printf '%s
\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
959 has_action "$todo" ||
962 cp "$todo" "$todo".backup
964 git_sequence_editor "$todo" ||
965 die_abort "$(gettext "Could not execute editor")"
967 has_action "$todo" ||
970 git rebase--interactive --check-todo-list || {
981 git_rebase__preserve_merges () {
982 initiate_action "$action"
984 if test $ret = 0; then
991 if test -z "$rebase_root"
993 mkdir "$rewritten" &&
994 for c in $(git merge-base --all $orig_head $upstream)
996 echo $onto > "$rewritten"/$c ||
997 die "$(gettext "Could not init rewritten commits")"
1000 mkdir "$rewritten" &&
1001 echo $onto > "$rewritten"/root ||
1002 die "$(gettext "Could not init rewritten commits")"
1005 init_revisions_and_shortrevisions
1007 format=$(git config --get rebase.instructionFormat)
1008 # the 'rev-list .. |
sed' requires %m to parse; the instruction requires %H to parse
1009 git rev-list --format="%m%H ${format:-%s}" \
1010 --reverse --left-right --topo-order \
1011 $revisions ${restrict_revision+^$restrict_revision} | \
1013 while read -r sha1 rest
1015 if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
1017 comment_out="$comment_char "
1022 if test -z "$rebase_root"
1025 for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
1027 if test -f "$rewritten"/$p
1035 if test f = "$preserve"
1037 touch "$rewritten"/$sha1
1038 printf '%s
\n' "${comment_out}pick $sha1 $rest" >>"$todo"
1042 # Watch for commits that been dropped by --cherry-pick
1044 # Save all non-cherry-picked changes
1045 git rev-list $revisions --left-right --cherry-pick | \
1046 sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
1047 # Now all commits and note which ones are missing in
1048 # not-cherry-picks and hence being dropped
1049 git rev-list $revisions |
1052 if test -f "$rewritten"/$rev &&
1053 ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
1055 # Use -f2 because if rev-list is telling us this commit is
1056 # not worthwhile, we don't want to track its multiple heads
,
1057 # just the history of its first-parent for others that will
1058 # be rebasing on top of it
1059 git rev-list
--parents -1 $rev | cut
-d' ' -s -f2 > "$dropped"/$rev
1060 sha1
=$
(git rev-list
-1 $rev)
1061 sane_grep
-v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1062 rm "$rewritten"/$rev