In git, how can one find out which files in directory have NOT changed since some commit?
3 Answers
IMO a far easier way to generate your list would be the following command chain:
git ls-files --full-name | grep -v "$(git diff --name-only <REF>)"
Where <REF>
is the hash of the commit from which you want the unchanged files since.
git ls-files
list, as you could expect, all versioned files and then you grep all files which aren't in the list of changed files since the specified commit.

- 534
- 5
- 8

- 18,810
- 4
- 51
- 73
-
1Note that this requires you to be in the top level of the repository, since `git ls-files` will only list files in and below the working directory. – William Pursell Jul 22 '14 at 00:09
-
Use git diff --name-only $REV
to get the list of files that have changed. Use git -C $(git rev-parse --show-toplevel) ls-tree -r HEAD --name-only
to get the list of all files. Use grep
to separate the sets:
git diff ${REV?must specify a REV} --name-only > /tmp/list
git -C $(git rev-parse --show-toplevel) ls-tree -r HEAD --name-only |
grep -f /tmp/list -v
Prior to executing those commands, you'll need to specify a rev in the variable REV. eg, REV=HEAD~6
or REV=branch-name~~

- 204,365
- 48
- 270
- 300
-
Ha! you should have just said 'learn to use git' :) I was looking for more simpler approach but I guess this is not so common task. – santervo Jul 21 '14 at 13:30
-
Is there a reason you don't use `git ls-files`? Then a list could be generated with `git ls-files | grep -v $(git diff --name-only )`. – Sascha Wolf Jul 21 '14 at 16:24
-
Note the suggested solutions treat file deletion after a commit as a change after it.
Also on a large git repo, the suggested one-liners did not work for me with the thrown error: grep: Argument list too long
.
So, I had to work with files:
$ git ls-files --full-name | sort > all.git
$ git diff --name-only <REF> | sort > recent.change
$ comm -12 all.git recent > recent.change.not.deleted
$ comm -13 all.git recent.change.not.deleted
comm
is a linux utility that shows common and unique lines in two files. Hopefully similar utilities exist for other platforms.

- 14,734
- 5
- 67
- 101