Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single command to find all git ignored files and why they are being ignored

Tags:

git

I can find out what files are being ignored with

git status --ignored

I can find out why one file is being ignored with

git check-ignore -v somefile

How to combine the two? My feeble attempts don't work. Expressions like

git check-ignore -v .

or

get check-ignore -v **/*

come up way short; they list only a tiny fraction of the files listed in git status --ignored. (For example, .DS_Store files don't appear at all.)

The best I could come up with, with my feeble unix fu, is:

git status --ignored | tr -d '\t' | git check-ignore --verbose --stdin

But it errors out on the final empty line of the status output, and it seems nutty that I have to play these pipe games at all.

like image 499
matt Avatar asked Oct 26 '25 14:10

matt


1 Answers

The swiss-army-knife of git aware file listing is git ls-files.

git ls-files --exclude-standard -oi

will list all unindexed ignored files. And git check-ignore has a --stdin option, so...

git ls-files --exclude-standard -oi | git check-ignore -vn --stdin

does what you want, about as fast as possible. I want that --exclude-standard option often enough that I have a global alias for it, git config --global alias.ls "ls-files --exclude-standard", so for me it'd be git ls -oi | git check-ignore -vn --stdin.

like image 65
jthill Avatar answered Oct 28 '25 05:10

jthill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!