Skip to main content

On Squashing Commits

Last updated in Winter 2021

Squashing commits should be the job of the developer making a pull request, not a blanket strategy to clean up your Git history.

I think individual commits have value and I think squashing should be used by the person making the pull request.

Atomic commits with good commit messages make git blame more useful and show a more accurate history of a codebase. If you squash every commit, then commit messages made alongside code changes don't matter.

Someone at my side job said this:

when working on one branch one developer may add 20 different commits with fixes, which just adds noise to master. Squashing properly keeps master clean.

If this developer is pushing commits that aren't atomic logical changes, the developer should squash their own commits before pushing to origin. If all 20 are logical commits, throwing away all the effort spent on making atomic commits and writing thoughtful commit messages is a waste and encourages developers to care little for the hygiene of their own commits.