注意:
也有趣的是(在
qwertymk的
答案中提到),你也可以使用
git check-ignore -v
命令,至少在Unix系统上(在CMD的Windows会话中
无法工作,但在Windows CMD git bash会话中可以工作)。
git check-ignore -- *
git check-ignore -v -- *
第二个显示了
.gitignore
的实际规则,该规则使文件在您的 git 存储库中被忽略。
在 Unix 上,使用 "
What expands to all files in current directory recursively?" 和 bash4+:
git check-ignore **/*
(或者使用
find -exec
命令)
注意:
https://stackoverflow.com/users/351947/Rafi B.在
评论中建议
避免(有风险的)globstar。
git check-ignore -v $(find . -type f -print)
确保从
.git/
子文件夹中排除这些文件。
CervEd在评论中建议避免使用.git/
。
find . -not -path './.git/*' | git check-ignore --stdin
原始答案(2009年)
git ls-files -i
应该可以工作,除了
它的源代码指出:
if (show_ignored && !exc_given) {
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
argv[0]);
exc_given
?
原来在-i
之后还需要一个参数才能真正列出任何内容:
尝试:
git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore
(但那只会列出您的缓存(非被忽略)对象,并带有过滤器,所以不完全符合您的要求)
例子:
$ cat .git/ignore
*.[oa]
$ cat Documentation/.gitignore
*.html
!foo.html
$ git ls-files --ignored \
--exclude='Documentation/*.[0-9]' \
--exclude-from=.git/ignore \
--exclude-per-directory=.gitignore
实际上,在我的“gitignore”文件(名为“exclude”)中,我找到了一个命令行,可以帮助你:
F:\prog\git\test\.git\info>type exclude
所以....
git ls-files --ignored --exclude-from=.git/info/exclude
git ls-files -i --exclude-from=.git/info/exclude
git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard
应该能解决问题。
(感谢honzajde在评论中指出git ls-files -o -i --exclude-from...
不包括缓存的文件:只有git ls-files -i --exclude-from...
(不带-o
)才包括。)
如ls-files手册页中所述,--others
是重要的部分,用于显示非缓存的、非提交的、通常被忽略的文件。
--exclude_standard
不仅仅是一个快捷方式,而是一种包括所有标准的“忽略模式”设置的方法。
exclude-standard
添加标准的git排除项:在每个目录中添加.git/info/exclude
和.gitignore
文件,以及用户的全局排除文件。
git clean
技巧)可以完成此操作的答案,正如 这里 所示。另外,我建议您不要在总结中使用“exclude-from”示例,因为这实际上没有注意任何.gitignore文件。我特别提出此请求,因为该页面是谷歌搜索的首要结果。 - Alexander Birdgit status --ignored
这个命令:https://git-scm.com/docs/git-status#Documentation/git-status.txt---ignoredltmodegt - Eduardo Pignatelligit check-ignore -v [PATH]
- meh