tags:

views:

29

answers:

1

I have a git repo, where I replaced a lot of files locally.

git status now shows many many modified files.

Some are "really modified", others only differ by line endings.

I want the ones that differ only by line endings to go away (git reset them), but I cannot seem to find the linux-piping-foo to make it happen.

Bonus points for how to remove files whose only difference is the executable bit.

+2  A: 

This will do it:

  git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| xargs git checkout HEAD --
  1. Run a diff of the working copy against the index and give a machine-readable summary for each file, ignoring changes in whitespace.
  2. Find the files that had no changes according to diff -b.
  3. Take their names.
  4. Pass them to git checkout against 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.

Aristotle Pagaltzis