How do I `git rebase -i` and prevent "You asked to amend the most recent commit, but doing so would make it empty."?
Seems like running:
git commit --allow-empty
git rebase --continue
Creates 2 squashed commits, instead of one.
Running git rebase -i some-hash
allows me to squash the 2 new commits into one.
If you are not rebasing a single commit and facing the same problem, the reason is the final result of your rebasing is an empty commit.
Assuming you don't want to commit the empty commit, let's say you have these two commits:
commit 1
commit 2
And you are getting the error when you want to merge these two commits (say by git rebase -i HEAD~2
), the fix is to reset those two commits by doing the following command for two times:
git reset HEAD^
I found the simplest solution was to just interactively rebase (git rebase -i {some head}
) and then drop the commits that were causing issues (with d
in the rebase screen).
If you know that the commits are direct mirrors of each other (squashing them will result in an empty commit), and trying to squash through rebase isn't working then simply removing the commits themselves works.
As painful as it sounds, you're fiddling with the history anyway so it helps to clean up.