Notes:
- 小白的answer更简单(git1.7.6+):
git status --ignored
(详见“有没有办法告诉 git-status 忽略 .gitignore 文件的影响?")
也很有趣(在qwertymk's answer),您还可以使用git check-ignore -v命令,至少在 Unix 上(不起作用在命令提示符中Windows会话,但在 Windows CMD git bash 会话中工作)
git check-ignore -- *
git check-ignore -v -- *
第二个显示了实际的规则.gitignore
这使得文件在你的 git 仓库中被忽略。
在 Unix 上,使用“什么递归扩展到当前目录中的所有文件?” 和 bash4+:
git check-ignore **/*
(or a find -exec
命令)
Note: https://stackoverflow.com/users/351947/Rafi B.建议在评论中 to 避免(有风险的)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
实际列出任何内容:
Try:
git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore
(但这只会列出你的cached(不可忽略的)对象,带有过滤器,所以这不完全是你想要的)
Example:
$ cat .git/ignore
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated html files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git ls-files --ignored \
--exclude='Documentation/*.[0-9]' \
--exclude-from=.git/ignore \
--exclude-per-directory=.gitignore
实际上,在我的“gitignore”文件(称为“排除”)中,我找到了一个可以帮助您的命令行:
F:\prog\git\test\.git\info>type exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
So....
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指出在评论中 that git ls-files -o -i --exclude-from...
does not包含缓存文件:仅git ls-files -i --exclude-from...
(without -o
) does.)
正如在ls 文件手册页, --others
是重要的部分,以便向您显示非缓存、非提交、通常被忽略的文件。
--exclude_standard
不仅仅是一个捷径,而是一种包含的方式all标准“忽略模式”设置。
exclude-standard
添加标准 git 排除:.git/info/exclude
, .gitignore
在每个目录中,以及user's global exclusion file
.