Last Updated: February 25, 2016
·
762
· larryaasen

Git diffs that are nothing

I was looking at this Git check-in today and notice many changes that showed up in the diff that were not really changes. I am not sure why diff identified them as changes, but maybe some tabs were converted to spaces or something like that. When lines of code are identified by diff as changed, but there are really no changes cause clutter in the commit. It is hard to determine exactly what has changed and others who review the code will have to spend extra time analyzing diffs that turn out to be nothing.

A good thing to remember to do before committing code to Git is to remove changes from your files that show up in diff, but are not really changes. Using the SourceTree app this can be done easily. It lets you discard parts of the file that show up in diff that really did not change. Check all of the changes in all of the files you plan to commit first, and then commit.

This will help others in the project and keep the commit logs clean.

4 Responses
Add your response

If your editor is stripping trailing whitespace whilst that isn't the project standards then that would probably need to be disabled.. if its the standard then hunt down the person and get them to set up their editor accordingly.

git add -p is good for selecting chunks of changes you want in a commit. I always use it even to select everything to ensure I dont commit anything by accident by git add .

over 1 year ago ·

git diff -b may save your eyes too :)

over 1 year ago ·

@vgrichina: I understand the little tricks to clean up the diffs, but that does not take the crap out of the repo. It is best to clean out every unnecessary character from the code before it is committed to the repo. Some people will be looking at the commits from a web based tool that does not strip out the junk.

over 1 year ago ·

@larryaasen sometimes the repo already contains unnecessary characters and you cannot do much about it (i.e. you of course would keep your commits clean, but you cannot force all the people to do it).

over 1 year ago ·