Search code examples
gitgit-rebase

How do I `git rebase -i` and prevent "You asked to amend the most recent commit, but doing so would make it empty."?


I want to run a git rebase -i some-hash.

When I run it, I get the error:

You asked to amend the most recent commit, but doing so would make it empty. You can repeat your command with --allow-empty, or you can remove the commit entirely with "git reset HEAD^".
[...]
Could not apply [...]

That error seems specific to a single commit, as --allow-empty isn't an option I can pass to rebase.

Apparently --keep-empty IS an option I can pass to git rebase, but it doesn't seem to fix the problem.

How can I rebase, and tell git, don't worry if a commit in the rebase is ends up having no effect?


Solution

  • 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.