哪个gitignore规则忽略了我的文件? [英] Which gitignore rule is ignoring my file?

查看:352
本文介绍了哪个gitignore规则忽略了我的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以看到为什么某些文件被git忽略(即 .gitignore 文件中的哪个规则导致文件被忽略)?

假设我有这个(或者更复杂的场景,有数百个文件夹和数十个 .gitignore 文件:

/ p>

  / 
-.gitignore
-folder /
-.gitignore
- 子文件夹/
-.gitignore
-file.txt

如果我运行 git add folder / subfolder / file.txt git可能会抱怨它被忽略:

 以下路径会被一个.gitignore文件忽略:
folder / subfolder / file.txt
如果您真的想添加它们,请使用-f

有什么办法可以知道所有可能的 .gitignore 中哪一个有规则忽略这个文件,并且显示规则?像:

 以下路径被您的文件夹/ .gi忽略tignore文件(第12行:* .txt)
文件夹/子文件夹/ file.txt
如果您真的想添加它们,请使用-f。

或者只是:

  $ git why-is-ignored folder / subfolder / file.txt 
folder / .gitignore:12:*。txt


解决方案

  git check-ignore -v filename 

请参阅该男子



原始答案如下:

git目前不提供这样的东西。但看到你的问题后,我做了一些谷歌搜索,发现在2009年此功能已被请求并部分实施。在阅读主题后,我意识到做好这件事并不是太多工作,所以我已经开始了一个补丁的工作,并希望在接下来的一两天内完成。我准备更新这个答案。



更新:哇,这比我想象的要困难得多。内部的 git 的排除处理是相当神秘的。无论如何,这里的几乎完成了一系列的提交,其中适用于今天的上游 master 分支。测试套件已完成99%,但我还没有完成对 - stdin 选项的处理。希望这个周末我能管理好,然后将我的补丁提交给git邮件列表。



与此同时,我绝对欢迎来自任何能够这样做 - 只需从我的 git 分叉克隆,请检查 check-ignore 分支并按正常方式进行编译。



UPDATE 2:完成了!最新版本是在上面的github上,我已经提交补丁系列git邮件列表进行同行评审。让我们看看他们的想法......



更新3:经过几个月的黑客/补丁评论/讨论/等待,我很高兴能够说这个功能现在已经达到了git的 master 分支,并将在下一个版本中提供(1.8.2,预计2013年3月8日)。以下是 check-ignore 手册页。 Phew,这是比我预期的更多的工作!



更新4:如果您对完整故事感兴趣,并且该功能已经实现,请查看 GitMinutes播客的第32集


Is there any way to see why some file is getting ignored by git (i.e. which rule in a .gitignore file is causing the file to be ignored)?

Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of .gitignore files:

/
-.gitignore
-folder/
    -.gitignore
    -subfolder/
              -.gitignore
              -file.txt

If I run git add folder/subfolder/file.txt git may complain of it being ignored:

The following paths are ignored by one of your .gitignore files:
folder/subfolder/file.txt
Use -f if you really want to add them.

Is there any way to know which of all the possible .gitignore have a rule to ignore this file, and also show the rule? Like:

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.

Or just:

$ git why-is-ignored folder/subfolder/file.txt
folder/.gitignore:12:*.txt

解决方案

git check-ignore -v filename

See the man page for more details.

Original answer follows:

git does not currently provide anything like this. But after seeing your question I did some googling and found that back in 2009 this feature was requested and partially implemented. After reading the thread, I realised it would not be too much work to do it properly, so I have started work on a patch and hope to have it finished in the next day or two. I will update this answer when it is ready.

UPDATE: Wow, that was a lot harder than I expected. The innards of git's exclude handling are quite cryptic. Anyway, here's an almost finished series of commits which apply to today's upstream master branch. The test suite is 99% complete, but I haven't finished handling of the --stdin option yet. Hopefully I'll manage that this weekend, and then submit my patches to the git mailing list.

In the meantime, I'd definitely welcome testing from anyone who's able to do so - just clone from my git fork, check out the check-ignore branch, and compile it as normal.

UPDATE 2: It's done! Latest version is on github as per above, and I have submitted the patch series to the git mailing list for peer review. Let's see what they think ...

UPDATE 3: After several more months of hacking / patch reviews / discussions / waiting, I'm delighted to be able to say that this feature has now reached git's master branch, and will be available in the next release (1.8.2, expected 8th March 2013). Here's the check-ignore manual page. Phew, that was way more work than I expected!

UPDATE 4: If you're interested in the full story about how this answer evolved and the feature came to be implemented, check out episode #32 of the GitMinutes podcast.

这篇关于哪个gitignore规则忽略了我的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆