Avoid adding “drive-by formatting changes” to commits

By Adrian Smith30 Apr 2015500 words3 mins to read

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:

This article was written by Adrian Smith on 30 Apr 2015

Follow me: Facebook | Twitter | LinkedIn | Email

More on: Coding | VCS | FAIL