You could use the auto squash feature of the git rebase
command to your advantage.
This would require an additional step beforehand, however, when creating the reverting commits:
Suppose you want to revert commit 1234
. Instead of doing
git revert 1234
or the equivalent from a graphical interface, you need to split this into
git revert --no-commit 1234
git commit --fixup 1234
Or you would need to edit the commit message manually to begin with "fixup!".
Now, when using git rebase -i --autosquash
, or when the rebase.autoSquash
option is enabled, the reverting commit will be automatically squashed with the original commit 1234
. If the two cancel each other out exactly, the resulting commit will be empty.
By doing the same rebase a second time, the now empty commit will automatically be omitted.