# Git: Allow-empty When Squashing

Many times in Git, we commit some work only to realize that is a mistake, and we should do another way. The easy way to fix that is to revert the previous commit, a process in which Git creates another commit that undoes exactly everything in the last commit. After that, we move on with the other way and check in commits for that. Before pushing everything to the remote branch, as responsible software engineers :), we sometimes want to “squash” the commits to erase the mistake to keep the commit log clean.

In the example shown below, my commit daefc6e was a mistake, and I reverted it with f3886c2 commit, and then I checked in my correct solution in b4cb02d commit. I wanted to squash those commits in an interactive rebase session, as seen in the following:

However, git rebase always fail in such situations with the following “error” message:

The error message is very confusing. When daefc6e and f3886c2 commits are squashed, the net effect is nothing, which is the “empty commit” mentioned in that error message. However, retrying the git rebase command with --allow-empty as said does not work.

Using git rebase --continue does not work as expected: it does not squash three commits into one.

After some Google searching, it turns out that the above error message comes from git commit --amend, which is delegated by git rebase to handle the squash. When the message says “repeat your command”, it means repeating the git commit --amend command, something would never occurs to us. Therefore, the right thing to do here is repeat commit and continue with the interactive rebase session:

By doing that, we will now have all three commits squashed into one and help cleaning up the commit log.