]> git.ipfire.org Git - thirdparty/git.git/commit
rebase -i: reword empty commit after fast-forward
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Tue, 11 Feb 2025 15:59:08 +0000 (15:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Feb 2025 17:50:53 +0000 (09:50 -0800)
commitaf8fc7be10fa486c93acfb177af4dd1fa7757deb
tree4c14cf2c0e780c3ce6d8348f253dcd7302380771
parentf93ff170b93a1782659637824b25923245ac9dd1
rebase -i: reword empty commit after fast-forward

When rebase rewords a commit it picks the commit and then runs "git
commit --amend" to reword it. When the commit is picked the sequencer
tries to reuse existing commits by fast-forwarding if the parents are
unchanged. Rewording an empty commit that has been fast-forwarded fails
because "git commit --amend" is called without "--allow-empty". This
happens because when a commit is fast-forwarded the logic that checks
whether we should pass "--allow-empty" is skipped. Fix this by always
passing "--allow-empty" when rewording a commit. This is safe because we
are amending a commit that has already been picked so if it had become
empty when it was picked we'd have already returned an error.

As "git commit" will happily create empty merge commits without
"--allow-empty" we do not need to pass that flag when rewording merge
commits.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3404-rebase-interactive.sh
t/t3430-rebase-merges.sh