Is there a way to show * only * whitespace differences using git diff?

I would like to capture all my space adjustments in their own commit so that everything else is clean of changes in spaces.

Easily filter out spaces using git diff using something like this

 git diff --ignore-all-space --ignore-space-change --ignore-space-at-eol --ignore-blank-lines 

but how do I get a list of only spaces?

(It would also be useful to get a list of files that have only spaces, so I can just add them all without skipping them with git add -p to highlight the differences in spaces. But I suppose it's secondary.)

+8
git whitespace
source share
1 answer

Here is one way:

  • Start with a clean working directory (e.g. git reset --hard )
  • Use Whitespace Total Fixer to clear all whitespace errors. There are options for fixing or ignoring various issues, but it might be fine by default:

     find . -name "*.whatever_extension_you_need" -exec wtf.py -v -i {} \; 
  • git diff will only show space changes now

  • Scene and commit changes only as spaces.

(FWIW, I wrote wtf.py ; I'm sorry if this sounds like shameless self-promotion, but I wrote it specifically for situations like this, where the repository is repeatedly infected by spaces that cause your commits.)

You can also use wtf.py to just check for space errors, rather than fixing them in place; this will not affect your files, but it will print (hopefully useful) stderr message about the problems that he found.

 > find . -name "*.whatever_extension_you_need" -exec wtf.py -v {} \; > /dev/null nightmare.txt LINE 8: WARNING: spaces followed by tabs in whitespace at beginning of line nightmare.txt: CHOPPED 1 lines with trailing space CHOPPED 0 blank lines at EOF ADDED newline at EOF CHANGED 1 line endings which didn't match crlf from first line WARNED ABOUT 1 lines with tabs/spaces mix 
+3
source share

All Articles