.gitignore中的否定模式如何工作? [英] How do negated patterns work in .gitignore?
问题描述
我试图使用带有否定模式的.gitignore文件(以!开头!),但它不能按我期望的方式工作。
,我有以下的目录结构:
C:/ gittest
- .gitignore
- aaa /
- bbb /
- file.txt
- ccc /
- otherfile.txt
在我的gitignore文件中,我有这个:
aaa /
!aaa / ccc /
我的理解(基于这个文档页面)是文件aaa / ccc / otherfile.txt不应该被忽略,但实际上git忽略了一切
我是否误解了这句话:一个可选的前缀!否定了模式;任何匹配的文件被先前的模式排除在外。?
顺便说一下,这是Windows上的msysgit 1.7.0.2。
> aaa / *
!aaa / ccc
您告诉它不要查看 aaa
,所以它甚至不检查路径 aaa / ccc
。如果使用通配符,它仍然会读取 aaa
的内容,那么每个条目都与通配符匹配并被忽略,除 aaa / ccc
将其放回。
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.
I think that what you actually want to do is:
aaa/*
!aaa/ccc
You're telling it "don't look in aaa
" so it never even examines the path aaa/ccc
. If you use the wildcard, it still reads the contents of aaa
, then each entry matches the wildcard and is ignored, except aaa/ccc
which gets put back in.
这篇关于.gitignore中的否定模式如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!