Reputation: 14360
Under a specific <directory>
(within a git repository),
I want a complete list of files that are:
.gitignore
).Is there an easy way to do this?
Note that while git status
does list untracked files that are not ignored,
it fails to list the actual files within any untracked sub-directories within the git repository.
Upvotes: 4
Views: 1383
Reputation: 14360
Yes, by using git ls-files
.
git ls-files -o --exclude-standard [directory]
.gitignore
in each directory, .git/info/exclude
and ~/.gitignore_global
.Here is a sample git repository with 2 new untracked local files. Both of which are in a newly added untracked directory. One of the untracked files matches a pattern *.o
specified in the .gitignore
.
~/linux-stable$ ls -lR kernel/untracked-dir/
kernel/untracked-dir/:
total 8
-rw-rw-r-- 1 cvs cvs 7 Sep 2 18:46 untracked-ignored-file.o
-rw-rw-r-- 1 cvs cvs 7 Sep 2 18:46 untracked-non-ignored-file.c
Running git status
simply lists the new untracked sub-directory and not the individual files within
~/linux-stable$ git status kernel/
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
kernel/untracked-dir/
nothing added to commit but untracked files present (use "git add" to track)
Whereas using
git ls-files -o --exclude-standard
, we get :~/linux-stable$ git ls-files -o --exclude-standard kernel/untracked-dir/untracked-non-ignored-file.c
i.e. the actual list of untracked-files (including the ones within any untracked directories).
Upvotes: 4