在Ryan Bates 关于git的Railscast中 ,他的.gitignore文件包含以下行:
tmp/**/*
使用星号后加星号的目的是什么: **/*
? 将使用简单的tmp/*
而不是tmp/**/*
不能达到完全相同的结果?
使用Googlesearch这个问题,我发现了一篇不太明确的IBM文章,我想知道是否有人能够澄清这个问题。
它说要进入tmp下面的所有子目录,以及tmp的内容。
例如我有以下几点:
$ find tmp tmp tmp/a tmp/a/b tmp/a/b/file1 tmp/b tmp/b/c tmp/b/c/file2
匹配输出:
$ echo tmp/* tmp/a tmp/b
匹配输出:
$ echo tmp/**/* tmp/a tmp/a/b tmp/a/b/file1 tmp/b tmp/b/c tmp/b/c/file2
这是zsh的默认功能,让它在bash 4中工作,你执行:
shopt -s globstar
来自http://blog.privateergroup.com/2010/03/gitignore-file-for-android-development/ :
(kwoods)
"The double asterisk (**) is not a git thing per say, it's really a linux / Mac shell thing. It would match on everything including any sub folders that had been created. You can see the effect in the shell like so: # ls ./tmp/* = should show you the contents of ./tmp (files and folders) # ls ./tmp/** = same as above, but it would also go into each sub-folder and show the contents there as well."
根据gitignore的文档 ,这个语法从git版本1.8.2开始支持。
这里是相关的部分:
与完整路径名相匹配的连续两个星号(
**
)可能有特殊含义:
前面的
**
后跟斜杠表示所有目录匹配。 例如,**/foo
匹配任何地方的文件或目录foo
,与patternfoo
相同。**/foo/bar
与直接在目录foo
下的任何地方的文件或目录**/foo/bar
相匹配。尾随
/**
匹配里面的所有内容。 例如,abc/**
匹配目录abc
中的所有文件,相对于.gitignore
文件的位置,具有无限深度。斜杠后跟两个连续的星号,则斜线匹配零个或多个目录。 例如,
a/**/b
匹配a/b
,a/x/b
,a/x/y/b
等等。其他连续的星号被认为是无效的。