Skip to content

Commit 8beb1f3

Browse files
dmpotgitster
authored andcommitted
git-rebase-interactive: do not squash commits on abort
If git rebase interactive is stopped by "edit" command and then the user said "git rebase --continue" while having some stage changes, git rebase interactive is trying to amend the last commit by doing: git --soft reset && git commit However, the user can abort commit for some reason by providing an empty log message, and that would leave the last commit undone, while the user being completely unaware about what happened. Now if the user tries to continue, by issuing "git rebase --continue" that squashes two previous commits. Signed-off-by: Dmitry Potapov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaefbfa commit 8beb1f3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

git-rebase--interactive.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,18 @@ do
427427
else
428428
. "$DOTEST"/author-script ||
429429
die "Cannot find the author identity"
430+
amend=
430431
if test -f "$DOTEST"/amend
431432
then
433+
amend=$(git rev-parse --verify HEAD)
432434
git reset --soft HEAD^ ||
433435
die "Cannot rewind the HEAD"
434436
fi
435437
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
436-
git commit --no-verify -F "$DOTEST"/message -e ||
437-
die "Could not commit staged changes."
438+
git commit --no-verify -F "$DOTEST"/message -e || {
439+
test -n "$amend" && git reset --soft $amend
440+
die "Could not commit staged changes."
441+
}
438442
fi
439443

440444
require_clean_work_tree

0 commit comments

Comments
 (0)