否定模式在 .gitignore 中如何工作?
我正在尝试使用带有否定模式的 .gitignore 文件(以 ! 开头的行),但它没有按我预期的方式工作。
作为一个最小的例子,我有以下目录结构:
C:/gittest
-- .gitignore
-- aaa/
-- bbb/
-- file.txt
-- ccc/
-- otherfile.txt
在我的 gitignore 文件中,我有这样的:
aaa/
!aaa/ccc/
我的理解(基于 这个文档页面)是文件aaa/ccc/otherfile.txt不应该被忽略,但事实上git忽略了aaa下的所有内容。
我是否误解了这句话:“一个可选的前缀!它否定了该模式;任何被先前模式排除的匹配文件将再次包含在内。”?
顺便说一句,这是在 Windows 上使用 msysgit 1.7.0.2。
I am attempting to use a .gitignore file with negated patterns (lines starting with !), but it's not working the way I expect.
As a minimal example, I have the folllowing directory structure:
C:/gittest
-- .gitignore
-- aaa/
-- bbb/
-- file.txt
-- ccc/
-- otherfile.txt
and in my gitignore file, I have this:
aaa/
!aaa/ccc/
My understanding (based on this doc page) is that the file aaa/ccc/otherfile.txt should not be ignored, but in fact git is ignoring everything under aaa.
Am I misunderstanding this sentence: "An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again."?
BTW, this is on Windows with msysgit 1.7.0.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你真正想做的是:
你告诉它“不要查看
aaa
”,所以它甚至从不检查路径aaa/ccc
。如果您使用通配符,它仍然读取aaa
的内容,然后每个条目与通配符匹配并被忽略,除了aaa/ccc
被放回。I think that what you actually want to do is:
You're telling it "don't look in
aaa
" so it never even examines the pathaaa/ccc
. If you use the wildcard, it still reads the contents ofaaa
, then each entry matches the wildcard and is ignored, exceptaaa/ccc
which gets put back in.如果您想排除
aaa
中的所有内容,但包含aaa/ccc
及其下面的所有内容,则应该使用:第一行告诉 git 忽略
aaa 下面的所有内容
,第二行告诉它不要忽略文件夹aaa/ccc
,它实际上“启用”了第三行,然后告诉它不要忽略aaa/ccc
下面的所有内容>。If you want to exclude everything in
aaa
, but includeaaa/ccc
and everything beneath it, you should use:The first line tells git to ignore everthing beneath
aaa
, the second tells it not to ignore the folderaaa/ccc
which actually "enables" the third line which then tells it not to ignore everything beneathaaa/ccc
.如果有人仍然没有在
git status
中看到新的未忽略的项目,那么事先运行git update-index
可以帮助 git 查看更改(至少在版本 1.9 中)。 gitbash 的 x)。If anyone's still not seeing newly un-ignored items in a
git status
running agit update-index
before hand can help git to see the changes (at least in version 1.9.x of gitbash).