Note: This was originally posted on my blog at https://therobinkim.com/blog/git-add-everything-but-whitespace-changes. Any updates will appear there and not here.
I was fixing some spelling errors in an open source repo in GitHub, but for some reason, when I went to
git diff to see which changes would be staged, I started seeing hundreds of whitespace edits I could've sworn I didn't intend to make. I tried to use
git add -p to tell git which whitespace edits to ignore, but it just wasn't feasible to parse through so many false hits!
So a quick Gogle search led to this Stack Overflow answer which suggests:
git diff -w | git apply --cached --ignore-whitespace
After this command:
git diff --cached shows the changes that have been be staged for commit (which is the stuff you want)
git diff shows all the whitespace changes that wasn't staged for commit (which is exactly what you wanna toss away)