You are here

Git: To squash or not to squash?

Posted by Steven

Until recently, I told my team to squash all of their commits on a given feature branch to just one commit. Every feature branch consisted of just this one commit and could be integrated into develop so that develop read just like a sequence of features. After further consideration, I changed that. Here are reasons for both approaches:

Pro-Squash:

Clean timeline: development of features clearly visible because every commit is a feature.

Commits representing work in progress (WIP) broke builds on CI-server.

WIP-commits prevented "jumping a month into the past" for debugging and exploratory purposes because they are potentially broken (compile errors, failing tests).

Anti-Squash:

If feature branches are merged, a merge commit is created that represents the development of a feature.

Tools like Git Bisect are much more powerful when dealing with small commits

In IDEs like IntelliJ IDEA, feature branches in the Git history can be collapsed to provide a better overview

Small tasks are better visible. For example, small bugfixes tended to be fixed in bigger feature branches, just to be never found again. "Yeah, this got fixed somewhere, but I don't know where"-syndrome.

Every commit causes the CI-server to build. The more (pushed) commits, the more builds, the faster feedback if something went wrong.