Reputation: 944
Got some changes I've pulled from another source as a tarball and I'd like to know which files have not changed. The destination is a Git clone, so it's easy to see what's new and what has changed. Anyone know a way to get a list of what has not changed (excluding untracked)?
EDIT: Said another way, I'm hoping to leverage Git to find what preexisting files (in Git) may be absent from the new copy (the tarball).
Upvotes: 7
Views: 1436
Reputation: 2045
With a bit of help:
comm -23 <(git ls-files | sort) <(git diff --name-only | sort)
See man comm
. This considers a list of all tracked files vs. a list of all modified files, and excludes ones that are only in the latter or are in both, leaving only unmodified files.
Upvotes: -1
Reputation: 81
I haven't been able to find pure git solution, but this is what worked for me:
diff <(git diff --name-only) <(git ls-files -- sub/dir) | grep "^>" | cut -b3-
Explanation of commands used:
git diff --name-only # list modified files
git ls-files -- sub/dir # list all git--tracked files in sub/dir
grep "^>" # match lines starting with '>', i.e. diff's marker for lines present in the second set but not in the first one (i.e. unmodified files)
cut -c3- # remove diff's marker (i.e. remove first two characters)
# <( command ) gives output of the command as a file (diff command needs two files to compare them)
Upvotes: 6
Reputation: 10084
Maybe:
$ git diff --name-only > tmpfile
$ git ls-files -X tmpfile
$ rm tmpfile
Upvotes: 1