为什么模式‘doc/frotz/’匹配‘doc/frotz目录’,而不匹配‘a/doc/frotz‘目录?
why the pattern ‘doc/frotz/’ matches ‘doc/frotz directory’, but not ‘a/doc/frotz‘ directory?
模式“doc/frotz/”匹配“doc/frotz”目录,但不匹配“a/doc/frotz”目录;但是‘frotz/’匹配‘frotz’和‘a/frotz’,这是一个目录。
这两个模式看起来很像,但为什么后者匹配两种情况而前者只匹配一种情况?
.gitignore
的文档说:
If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.
只要你在某处有一个斜杠(但忽略末尾的斜杠),那么模式只会从 .gitignore
所在的目录开始匹配,而不是在较低的目录中。
在您的例子中,目录 a/doc/frotz
不是以模式 doc/frotz
开头的,因此它不匹配。您的第二个模式 frotz
不是以这种方式锚定的,匹配也是如此。
模式“doc/frotz/”匹配“doc/frotz”目录,但不匹配“a/doc/frotz”目录;但是‘frotz/’匹配‘frotz’和‘a/frotz’,这是一个目录。
这两个模式看起来很像,但为什么后者匹配两种情况而前者只匹配一种情况?
.gitignore
的文档说:
If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.
只要你在某处有一个斜杠(但忽略末尾的斜杠),那么模式只会从 .gitignore
所在的目录开始匹配,而不是在较低的目录中。
在您的例子中,目录 a/doc/frotz
不是以模式 doc/frotz
开头的,因此它不匹配。您的第二个模式 frotz
不是以这种方式锚定的,匹配也是如此。