Skip to content

Commit c14c3c8

Browse files
dmpotgitster
authored andcommitted
git-rebase--interactive: auto amend only edited commit
"git rebase --continue" issued after git rebase being stop by "edit" command is trying to amend the last commit using stage changes. However, if the last commit is not the commit that was marked as "edit" then it can produce unexpected results. For instance, after being stop by "edit", I have made some changes to commit message using "git commit --amend". After that I realized that I forgot to add some changes to some file. So, I said "git add file" and the "git rebase --continue". Unfortunately, it caused that the new commit message was lost. Another problem is that after being stopped at "edit", the user adds new commits. In this case, automatic amend behavior of git rebase triggered by some stage changes causes that not only that the log message of the last commit is lost but that it will contain also wrong Author and Date information. Therefore, this patch restrict automatic amend only to the situation where HEAD is the commit at which git rebase stop by "edit" command. Signed-off-by: Dmitry Potapov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8beb1f3 commit c14c3c8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

git-rebase--interactive.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ do_next () {
284284
pick_one $sha1 ||
285285
die_with_patch $sha1 "Could not apply $sha1... $rest"
286286
make_patch $sha1
287-
: > "$DOTEST"/amend
287+
git rev-parse --verify HEAD > "$DOTEST"/amend
288288
warn "Stopped at $sha1... $rest"
289289
warn "You can amend the commit now, with"
290290
warn
@@ -431,6 +431,10 @@ do
431431
if test -f "$DOTEST"/amend
432432
then
433433
amend=$(git rev-parse --verify HEAD)
434+
test "$amend" = $(cat "$DOTEST"/amend) ||
435+
die "\
436+
You have uncommitted changes in your working tree. Please, commit them
437+
first and then run 'git rebase --continue' again."
434438
git reset --soft HEAD^ ||
435439
die "Cannot rewind the HEAD"
436440
fi

0 commit comments

Comments
 (0)