有什么办法可以查看为什么git会忽略某些文件(即.gitignore
文件中的哪个规则导致该文件被忽略)?
想象一下我有这种情况(或更复杂的情况,有数百个文件夹和数十个.gitignore
文件:
/
-.gitignore
-folder/
-.gitignore
-subfolder/
-.gitignore
-file.txt
如果我运行git add folder/subfolder/file.txt
git可能会抱怨它被忽略了:
The following paths are ignored by one of your .gitignore files:
folder/subfolder/file.txt
Use -f if you really want to add them.
有什么方法可以知道在所有可能.gitignore
的规则中忽略该文件并显示该规则吗?喜欢:
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.
要不就:
$ git why-is-ignored folder/subfolder/file.txt
folder/.gitignore:12:*.txt
git check-ignore
很快(git1.8.5 / 1.9)会有一个--no-index
选择。请参阅下面的答案