Last Updated: February 25, 2016
·
349
· jtai

Resetting Whitespace-Only Changes in Git

I used find -exec with sed to do a repository-wide find/replace this morning. Unfortunately, some of the files in the repository didn’t have a newline at the end of the file, but sed added one. I wanted a one-liner to reset all the whitespace-only changes, and I found it on stackoverflow:

git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| xargs git checkout HEAD --

This tip was reposted from my blog, jontai.me