[英]How to ignore to level directory in Git but not other directories starting with same name?
How to ignore top level cache
but not 'apps/cache'? 如何忽略顶级
cache
而不忽略“应用程序/缓存”?
I have such structure. 我有这样的结构。
cache
apps/cache
conf/cache
I want to write rules to ignore only top level cache
. 我想编写规则以仅忽略顶级
cache
。
cache - IGNORE
apps/cache - NOT IGNORE
conf/cache - NOT IGNORE
How to do in git? 如何在git中做?
Just prefix the directory to be ignored with /. 只需在目录前面加上/即可。 This will ignore the mentioned files/directories only in the directory where .gitignore is present.
这只会忽略存在.gitignore的目录中提到的文件/目录。
eg: /cache 例如: / cache
Just provide the full path to your cache directory: 只需提供您的缓存目录的完整路径即可:
/cache
This way, things like app/cache and conf/cache won't be included. 这样,将不会包含诸如app / cache和conf / cache之类的内容。
Note: the ability to anchor the path to the current folder of a git repo comes from commit d0bfd02 (April 2007, git 1.5.2-rc0) : 注意:将路径锚定到git repo的当前文件夹的能力来自commit d0bfd02(2007年4月,git 1.5.2-rc0) :
Add basic infrastructure to assign attributes to paths
添加基本基础架构以将属性分配给路径
This adds the basic infrastructure to assign attributes to paths, in a way similar to what the exclusion mechanism does based on
$GIT_DIR/info/exclude
and.gitignore
files.这将添加基本的基础结构,以将属性分配给路径,其方式类似于基于
$GIT_DIR/info/exclude
和.gitignore
文件的排除机制。Each line in these files defines a pattern matching rule.
这些文件中的每一行都定义了一个模式匹配规则。
The first token on the line is a shell glob pattern.
该行上的第一个标记是外壳全局模式。
For glob matching, the same "if the pattern does not have a slash in it, the basename of the path is matched with
fnmatch(3)
against the pattern, otherwise, the path is matched with the pattern with FNM_PATHNAME" rule as the exclusion mechanism is used.对于全局匹配,相同的规则是:“如果模式中没有斜线,则将路径的基本名称与
fnmatch(3)
相对于模式进行匹配,否则,将路径与具有FNM_PATHNAME的模式进行匹配”作为排除规则机制。
That is why the documentation soon included (June 2007, git 1.5.2.1): 这就是为什么文档很快包含在内的原因 (2007年6月,git 1.5.2.1):
A leading slash matches the beginning of the pathname;
前导斜杠与路径名的开头匹配;
for example, "/*.c
" matches "cat-file.c
" but not "mozilla-sha1/sha1.c
"例如,“
/*.c
”匹配“cat-file.c
”,但不匹配“mozilla-sha1/sha1.c
”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.