Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to list the unmodified files in Git?

Tags:

git

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).

like image 415
Paul R Rogers Avatar asked Sep 28 '22 13:09

Paul R Rogers


2 Answers

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)
like image 73
DEVoytas Avatar answered Nov 06 '22 02:11

DEVoytas


Maybe:

$ git diff --name-only > tmpfile
$ git ls-files -X tmpfile
$ rm tmpfile
like image 45
Sukima Avatar answered Nov 06 '22 02:11

Sukima