When creating and applying patches, git often complains about whitespace errors. Whitespace changes are generally not desirable, because they make the diff longer and diverts your focus from (very probably) more important changes. From this reason git tries to provide warnings for whitespace changes that might have not been needed. This includes trailing whitespace, spaces before tabs in indentation and empty newlines at the end of a file.
If you execute
$ git diff
and have colored output enabled, git marks these changes with light red background.
But if you don’t have colored output enabled, or maybe your patch is too long and you don’t want to scroll through it, there’s an easier way to check for whitespace errors. Just execute
$ git diff --check
You can then receive output like this:
$ git diff --check README:7: trailing whitespace. +or ask in #fedora-qa on the freenode IRC network. README:13: space before tab in indent. + 'autoqa' is the main binary that kicks off tests TODO:14: new blank line at EOF.
And now you know what to fix.
If you’re working on a patch for some project and you’re about to send it, use this simple command to check for whitespace errors. It will then save a little work for everyone who’s going to read the diff (or the commit log).