Avoid adding “drive-by formatting changes” to commits

Recently, when reviewing code, I saw a commit resembling the following:

- if (x) foo();
- if (y) bar();
+ if (y) {
+    bar();
+ }

It's not easy to see that of the two "if" statements, only one was actually deleted. The other had its formatting changed, but was otherwise not altered.

To prevent this, go through the "diff" before doing the commit. Revert any changes which have happened which haven't changed the functionality of the code.

Committing not only the things you meant to change, but a bunch of other changes that don't change the code's functionality, has the following negative consequences:

I think there are the following reasons why such changes might get introduced in the first place:

P.S. I recently created a nerdy privacy-respecting tool called When Will I Run Out Of Money? It's available for free if you want to check it out.

This article is © Adrian Smith.
It was originally published on 30 Apr 2015
More on: Coding | VCS | FAIL