How to Fixup a Commit
Do you fixup your git commits? Fixup is a tool to change any git commit, without much trouble.
So, I have three commits in my branch with the following messages:
- Commit A
- Commit B
- Commit C
After a code review, I want to apply some changes to commit A, which is the earliest (so a simple git amend won’t suffice):
$ git add .
$ git commit --fixup <SHA-of-A>
So, now I have 4 commits:
- Commit A
- Commit B
- Commit C
- fixup! Commit A
I can now do an interactive rebase to “fixup” commit A:
$ git rebase --autosquash -i HEAD~4
The editor opens, but the last commit is automatically moved to after commit A, and the verb is correctly set to “fixup” (which is the same as squash, only that the commit message is not preserved):
pick 292ad0da8d Commit A
fixup 7716e4fbce fixup! Commit A
pick a42a458fb6 Commit B
pick 5a7382afe2 Commit C
Just save and exit, and it’s a bingo!