My repo has a big .gitignore
. I also have some rules in my .git/info/exclude
because I do not want my workflow to affect the repo: I use certain tools, and certain processes which generate files, that I do not want to neither be commited to the repo, nor be listed in the .gitignore
. Those are my "private ignored files".
In a recent project, I have experienced a funny situation: running some tests with some excluded files present break the tests in strange ways. Therefore, before I run the tests (which take hours to run), I need to make sure that I got rid of annoying private files.
Listing all excluded files is not an option:
git ls-files --other
This produces a list too big for being of any use.
And this:
git ls-files --other --exclude-standard
Does not list files excluded via the rules of .git/info/exclude
(or via .gitignore
)
This does the opposite of what I want:
git ls-files -o -X .git/info/exclude
Lists all ignore files except those in .git/info/exclude
This goes in the right direction:
git ls-files -o -X .gitignore
But then I need to find all .gitignore
in all folders manually (the repo is very large and has lots of .gitignore
)
This is nice:
git check-ignore -v *
But is not recursive, and there is no recurse
option.
I assume I could diff these two:
git ls-files -o
git ls-files -o -X .git/info/exclude
But really!? is there no better way to list the files excluded by one particular rule file?
This is the closer I get:
find . -type f | git check-ignore -v --stdin | grep '\.git/info/exclude'
It only lists files (which I think is what git
tracks anyway), and it is slow. I would expect an internal git
command to be faster.
The command you're looking for is:
git ls-files --ignored --others --exclude-from=.git/info/exclude
In other words, you forgot to include the --ignored
option to show just the ignored files.
The --ignored
option is used in conjunction with either --cached
, to show the ignored files already in the index, or --others
, to show the ignored untracked files.
Besides Enrico Compidoglio's answer—which is probably the best way to do this in an automated fashion—you could also temporarily hide (i.e., rename) the .git/info/exclude
file and use git ls-files --other --exclude-standard
, then un-hide your personal exclusion file. The drawback to trying to automate this is that if two entities attempt it "at the same time", or while other Git operations are running, the lack of atomicity shows. That is, there are three steps involved and the Git repository is therefore in "before", "during", and "after" states and should not be used by anything in the "during" state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With