Published at
Updated at
Reading time
1min
This post is part of my Today I learned series in which I share all my web development learnings.

Who doesn't know these commits only fixing a typo or removing a log message?

Personally I'm a big fan of the --amend flag to avoid these kind of commits. --amend lets you add changes to the last commit and rewrites it (you have to force push afterwards).

But what can you do when you want to fix a commit surrounded by other commits? You could surely do some "git magic" but usually this then is too much effort for me and I take the ugly commit.

My colleague Benedikt recently showed me how they work in the Contentful ecosystem and how they deal with situations that need fixes for commits that are right between several other commits.

The key commands to use are:

  • git commit --fixup <commit>
  • git rebase -i --autosquash

I could now describe how this works but yeah... Florent Lebreton wrote an excellent article on that so just head over there. ;)

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly — Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles