在Ryan Bates的Railscast about git,他的.gitignore文件包含以下行:Unix通配符选择器? (星号)
tmp/**/*
什么是使用双星号后跟一个星号这样的目的:**/*
? 会使用简单的tmp/*
而不是tmp/**/*
达不到完全相同的结果?
使用谷歌搜索这个问题,我发现了一篇关于它的不清楚的IBM文章,我想知道是否有人能够澄清这个问题。
在Ryan Bates的Railscast about git,他的.gitignore文件包含以下行:Unix通配符选择器? (星号)
tmp/**/*
什么是使用双星号后跟一个星号这样的目的:**/*
? 会使用简单的tmp/*
而不是tmp/**/*
达不到完全相同的结果?
使用谷歌搜索这个问题,我发现了一篇关于它的不清楚的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."
根据the documentation of gitignore,这句法因为Git版本1.8.2支持。
下面是相关部分:
两个连续的星号(
**
)的模式对全路径名匹配可能有特殊的含义:
领先
**
跟一个斜线意味着比赛所有目录。例如,**/foo
与任何地方的文件或目录foo
匹配, 与模式foo
相同。**/foo/bar
与直接在目录foo
下的任何地方的文件或目录bar
匹配。尾随
/**
匹配里面的所有内容。例如,abc/**
匹配目录abc
内的所有文件,相对于 的.gitignore
文件的位置具有无限深度。斜线后跟两个连续的星号,则斜线匹配零个或多个目录。例如,
a/**/b
匹配a/b
,a/x/b
,a/x/y/b
等等。其他连续的星号被认为是无效的。
注:虽然有些shell支持这种语法,但Git不支持。在'.gitignore'文件中,这相当于'tmp/*/*'。 – hammar 2012-10-02 07:09:02