Improved git workflow with fixup and autosquash
- Published at
- Updated at
- Reading time
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
- How to apply directory dependent git configuration using conditional imports
- How to add a directory but ignore included files in git
- A git alias to show a detailed git branch overview
- How to use git's file diff outside of git repositories
- git commit accepts several message flags (-m) to allow multiline commits