有没有用星号不能替代的用法?
Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo". A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth. A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. Other consecutive asterisks are considered invalid.
https://git-scm.com/docs/gitignore#_pattern_format
让我指出,我只问有关前导星号/斜杠冗余的问题。由于似乎**/foo/bar
可以用简单的方法代替foo/bar
例如,我的.gitignore
文件中包含以下内容:
Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo". A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth. A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on. Other consecutive asterisks are considered invalid.
我想知道为什么他们不能简单地写:
# NuGet Packages
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
不可以,**/
仅当其余模式除尾部斜杠以外不包含斜杠时,前导符才作废。
我认为https://git-scm.com/docs/gitignore上的文档有点误导
If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).
但实际上仅与文件或目录的名称匹配,而不与整个路径匹配。
因此可以进行任何深度的**/packages/build
匹配packages/build
。
packages/build
因为它包含一个斜杠实际上与忽略文件相同,/packages/build
并且仅packages/build
在与忽略文件相同的级别上匹配。
另一方面,在任何深度都build
匹配build
,因此实际上与相同**/build
。
而/build
仅匹配build
在与忽略文件相同的级别上进行。
它始终取决于模式(在删除尾部斜线(如果存在)之后)是否包含任何斜线。