Is there any way to see why some file is getting ignored by git (i.e. which rule in a .gitignore
file is causing the file to be ignored)?
Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of .gitignore
files:
/
-.gitignore
-folder/
-.gitignore
-subfolder/
-.gitignore
-file.txt
If I run git add folder/subfolder/file.txt
git may complain of it being ignored:
The following paths are ignored by one of your .gitignore files:
folder/subfolder/file.txt
Use -f if you really want to add them.
Is there any way to know which of all the possible .gitignore
have a rule to ignore this file, and also show the rule? Like:
The following paths are ignored by your folder/.gitignore file (line 12: *.txt)
folder/subfolder/file.txt
Use -f if you really want to add them.
Or just:
$ git why-is-ignored folder/subfolder/file.txt
folder/.gitignore:12:*.txt
git check-ignore
will soon (git1.8.5/1.9) have a--no-index
option. See my answer below – VonCGIT_TRACE_EXCLUDE=1 git status
will soon be an additional way to debug.gitignore
rules. See my edited answer below – VonC