This will do it:
git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| xargs git checkout HEAD --
- Run a diff of the working copy against the index and give a machine-readable summary for each file, ignoring changes in whitespace.
- Find the files that had no changes according to
diff -b. - Take their names.
- Pass them to
git checkoutagainst the branch tip.
This pipe will do something sensible for each step you leave off, so you can start off with the just the first line and add more to see what happens at each step.
A possibly useful alternative last line:
| git checkout-index --stdin
This would reset the files to their staged contents instead of to their last committed state.
You may also want to use git diff HEAD on the first line instead, to get a diff of the working copy against the last commit instead of against the index.
Note: if you have filenames with spaces in them, you will first need to add a tr:
git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| tr '\n' '\0' \
Then you must add a -0/-z switch to whichever final command you wanted to use:
| xargs -0 git checkout HEAD --
# or
| git checkout-index --stdin -z