Logan Bailey

Adventures In Web Development

Blog, About, GitHub, and LinkedIn

I'm a big fan of rewriting my commit history before submitting my pull requests for approval. I generally boot up rebase interactive and slowly break up large commits into smaller ones and re-arrange commits so they can be squashed. I create temporary commit messages like "fixup this commit into this one". This is a slow process, but luckily there's an easier way around it.

Imagine a commit history that looks as follows:

$ git log --oneline
c0642a3 Edit Profile Templates
16cf8f5 User Controller For Account Management

During review, you notice a typo in 16cf8f5. You fix the typo but instead of creating a commit message the normal way you run git commit --fixup 16cf8f5. This will create a commit with the following message: fixup! User Controller For Account Management. This is the exact syntax expected by git rebase -i --autosquash 16cf8f5^, when you run that you'll see the following output:

pick 16cf8f5 User Controller For Account Management
fixup f24b82f fixup! User Controller For Account Management
pick c0642a3 Edit Profile Templates

You can then exit and as long as there aren't any merge conflicts your typo should be fixed.

All together:

To fix a typo in any commit in your working branch, identify the commit you introduced the typo at, lets assume it's 16cf8f5.

  1. Fix typo
  2. Stage file and run git commit --fixup 16cf8f5
  3. git rebase -i --autosquash 16cf8f5^
  4. Save and exit your text editor
Posted In:
git