【发布时间】:2012-08-22 02:20:36
【问题描述】:
有什么方法可以查看为什么某些文件被 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选项。见my answer below -
注意:
GIT_TRACE_EXCLUDE=1 git status很快将成为调试.gitignore规则的另一种方式。见my edited answer below