这是我当前目录的内容.
$ ls
foo.foo
$ ls -a
. .. .bar.foo .foo foo.foo .gitignore
Run Code Online (Sandbox Code Playgroud)
然后我将此目录转换为git存储库.
$ git init
Initialized empty Git repository in /home/lone/foo/.git/
$ ls -a
. .. .bar.foo .foo foo.foo .git .gitignore
Run Code Online (Sandbox Code Playgroud)
这是内容.gitignore
.
$ cat .gitignore
*.foo
Run Code Online (Sandbox Code Playgroud)
我看到模式的.gitignore
行为与shell中的相同模式不同.在shell *.foo
中只匹配非隐藏文件,即不以句点开头的文件名.
$ echo *.foo
foo.foo
Run Code Online (Sandbox Code Playgroud)
但是,*.foo
在.gitignore
似乎匹配任何文件,隐藏或不隐藏,随结束.foo
.
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
我在哪里可以了解更多关于.gitignore遵循的模式的精确定义,以便我可以理解它的行为与shell glob模式的行为不同的地方和原因?
Von*_*onC 10
gitignore
使用' *
'遵循glob约定:
Git将模式视为适合于消费的shell glob
fnmatch
(3)使用FNM_PATHNAME
标志:模式中的通配符/
与路径名中的a不匹配.例如,"
Documentation/*.html
"匹配"Documentation/git.html
"但不匹配"Documentation/ppc/ppc.html
"或"tools/perf/Documentation/perf.html
".
shell是否也使用
fnmatch
(3)来处理glob模式?
在这种情况下,为什么*
之前不匹配零个字符.(即隐藏文件)但gitignore呢?
因为这是shell配置的选择.
shopt -s dotglob
echo *.foo
.foo foo.foo
Run Code Online (Sandbox Code Playgroud)
那是使用dotglob