Git命令显示哪些特定文件被.gitignore忽略 [英] Git command to show which specific files are ignored by .gitignore
问题描述
我的项目源码树:
/
|
+ - src /
+ ---- refs /
+ ----...
|
+ - 供应商/
+ ----...
我在我的供应商分支中有代码(目前是MEF),我将在那里编译,然后将引用移动到项目从中选择它们的 / src / refs
。
我的问题是我的 .gitignore
设置为忽略 *。dll
和 *。pdb
。我可以做一个 git add -f bar.dll
来强制添加被忽略的文件,这是好的,问题是我无法弄清楚列出哪些文件存在被忽略。
我想列出被忽略的文件,以确保我不会忘记添加它们。
我已阅读 git ls-files
的手册页,但无法使其正常工作。在我看来, git ls-files --exclude-standard -i
应该做我想做的事。我缺少什么?
更新:
git ls-files -i
将不起作用,您将收到错误信息:
ls-files: - 签名需要一些排除模式
git ls-files --others - 我--exclude-from = .git / info / exclude
,因为下面的VonC建议的确是答案。 - exclude-standard
选项也可以代替 - exclude-from
。
运行总结:
git ls-files --others -i --exclude- from = .git / info / exclude
git ls-files --others -i --exclude-standard
- xiaobai 的答案更简单(git1.7.6 +):
git status --ignored
(详见是否有办法告诉git-status忽略.gitignore
文件的影响?) - MattDiPasquale 的 answer (被提高)
git clean -ndX
适用于旧的gits,显示忽略的文件可以被删除的内容( )
同样有趣(在中提及qwertymk 的答案),你也可以使用 git check-ignore -v
命令,至少在Unix上(在CMD Windows 会话中不起作用)
git check-ignore *
git check-ignore -v *
第二个其中一个显示 .gitignore
的实际规则,这会使git repo中的文件被忽略。
在Unix上,使用扩展到所有文件在当前目录中递归?和bash4 +:
pre $ git check-ignore ** / *
(或 find -exec
命令)
原始回答42009)
git ls-files -i
应该可以工作,除其源代码表示:
if(show_ignored&& !exc_given){
fprintf(stderr,%s:--ignored needs some exclude pattern \\\
,
argv [0]);
exc_given
?
事实证明,在 -i
之后需要多一个参数来实际列出任何内容:
Try:
git ls-files -i --exclude-from = [Path_To_Your_Global] .gitignore
(但那只会列出您的 cached (未忽略)对象,过滤器,所以这不是你想要的)
示例:
$ cat .git / ignore
#忽略树中任何位置的对象和存档。
。[oa]
$ cat文档/ .gitignore
#忽略生成的html文件,
* .html
#除了手工维护的foo.html
!foo.html
$ git ls-files --ignored \
--exclude ='文档/ *。[0-9]'\
--exclude -from = .git / ignore \
--exclude-per-directory = .gitignore
< hr>
实际上,在我的'gitignore'文件(称为'exclude')中,我找到了一个可以帮助你的命令行:
F:\prog\git\test\.git\info>类型不包括
#git ls-files --others --exclude-from = .git / info / exclude
#以'#'开头的行是注释。
#对于大多数情况下以C语言编写的项目,以下是一组很好的
#排除模式(如果要使用它们,请取消注释):
#*。[oa]
$ *
所以....
git ls-files --others --ignored --exclude-from = .git / info / exclude
git ls-files -o -i --exclude -from = .git / info / exclude
git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard
应该这样做。
在 ls-files手册页中, - 其他
是重要的一部分,为了向您展示非缓存的,未提交的,通常被忽略的文件。
- exclude_standard
不仅仅是一个快捷方式,而且是一种包含所有标准忽略模式设置的方式。
exclude-standard
在每个目录中添加标准的git排除:.git / info / exclude
,.gitignore
,用户的全局排除文件
。
I am getting my feet wet on git and have the following issue:
My project source tree:
/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...
I have code (currently MEF) in my vendor branch that I will compile there and then move the references into /src/refs
which is where the project picks them up from.
My issue is that I have my .gitignore
set to ignore *.dll
and *.pdb
. I can do a git add -f bar.dll
to force the addition of the ignored file which is ok, the problem is I can not figure out to list what files exist that are ignored.
I want to list the ignored files to make sure that I don't forget to add them.
I have read the man page on git ls-files
and can not make it work. It seems to me that git ls-files --exclude-standard -i
should do what I want. What am I missing?
UPDATE:
git ls-files -i
will not work, you get the error:
ls-files: --ignored needs some exclude pattern
git ls-files --others -i --exclude-from=.git/info/exclude
as VonC suggested below is indeed the answer. The --exclude-standard
option also works instead of --exclude-from
.
Summary of what works:
git ls-files --others -i --exclude-from=.git/info/exclude
git ls-files --others -i --exclude-standard
Notes:
- xiaobai's answer is simpler (git1.7.6+):
git status --ignored
(as detailed in "Is there a way to tell git-status to ignore the effects of.gitignore
files?") - MattDiPasquale's answer (to be upvoted)
git clean -ndX
works on older gits, displaying a preview of what ignored files could be removed (without removing anything)
Also interesting (mentioned in qwertymk's answer), you can also use the git check-ignore -v
command, at least on Unix (doesn't work in a CMD Windows session)
git check-ignore *
git check-ignore -v *
The second one displays the actual rule of the .gitignore
which makes a file to be ignored in your git repo.
On Unix, using "What expands to all files in current directory recursively?" and a bash4+:
git check-ignore **/*
(or a find -exec
command)
Original answer 42009)
git ls-files -i
should work, except its source code indicates:
if (show_ignored && !exc_given) {
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
argv[0]);
exc_given
?
It turns out it need one more parameter after the -i
to actually list anything:
Try:
git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore
(but that would only list your cached (non-ignored) object, with a filter, so that is not quite what you want)
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
Actually, in my 'gitignore' file (called 'exclude'), I find a command line that could help you:
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 --others --ignored --exclude-from=.git/info/exclude
git ls-files -o -i --exclude-from=.git/info/exclude
git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard
should do the trick.
As mentioned in the ls-files man page, --others
is the important part, in order to show you non-cached, non-committed, normally-ignored files.
--exclude_standard
is not just a shortcut, but a way to include all standard "ignored patterns" settings.
exclude-standard
Add the standard git exclusions:.git/info/exclude
,.gitignore
in each directory, and theuser's global exclusion file
.
这篇关于Git命令显示哪些特定文件被.gitignore忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!