How to mask meaningless “fix typo” commit messages

Daniel Megyesi
Infrastructure adventures
3 min readAug 10, 2018

This article is part of my “short notes for myself, maybe useful for others too” series.

Many times I end up making typos during my development workflow. Naturally, these will either get their own commit with a particularly meaningful message attached: “typo”, “fix typo”, “fix” or similar. Some worse cases these corrections will just simply go to the next commit and reverting these commits later easily become a nightmare.

I have recently learnt how to use git’s squash, rebase and fixup features which are designed exactly for this use-case: keep the commit history clean from useless commits.

Photo by rawpixel on Unsplash

If you didn’t push your branch at all, editing the commit history won’t cause any problems for anyone. On the contrary, if this is a branch which has already been uploaded to the remote repository, you are going to need to do a force push operation — depending on your repository settings, you might not have the permissions to do this.

(If this is a short-living feature branch only used by you, I normally don’t see any problems with force pushing to it. After all, only the merge to the main branch will be interesting for everyone.)

There’s an amazing article in the Gitlab blog which I bumped into:

Allow me to copy here my favourite part; all the following is from the mentioned article — thanks Gitlab guys! :)

tl;dr git commit --fixup for each commit (instead of writing a custom message) then git rebase -i <hash of last good commit> --autosquash

Self-correcting fixup commits

If you know exactly which commit you want to fixup, when committing you don’t have to waste brain cycles thinking of good temporary names for “Fix 1”, “Fix 2”, …, “Fix 42”.

Step 1: Meet --fixup

After you’ve staged the changes fixing whatever it is that needs fixing, just commit the changes like this:

git commit --fixup c22a3fa0c5c

(Note that this is the hash for the commit c22a3fa0c5c Render navigation partial)

This will generate this commit message: fixup! Render navigation partial.

Step 2: And the sidekick --autosquash

Easy interactive rebase. You can have git place the fixups automatically in the right place.

git rebase -i 4155df1cdc7 --autosquash

History will be shown like so:

pick 4155df1cdc7 Page Navigation View
pick c22a3fa0c5c Render navigation partial
fixup 62e858a322 Fix a typo
fixup 5c25eb48c8 Ops another fix
fixup 7f0718efe9 Fix 2
fixup f0ffc19ef7 Argh Another fix!
pick aa0a35a867e Add styles for navigation

Ready for you to just review and proceed.

If you’re feeling adventurous you can do a non-interactive rebase git rebase --autosquash, but only if you like living dangerously, as you'll have no opportunity to review the squashes being made before they're applied.

--

--