【发布时间】:2016-04-26 09:40:24
【问题描述】:
这是我当前目录的内容。
$ ls
foo.foo
$ ls -a
. .. .bar.foo .foo foo.foo .gitignore
然后我把这个目录变成一个git仓库。
$ git init
Initialized empty Git repository in /home/lone/foo/.git/
$ ls -a
. .. .bar.foo .foo foo.foo .git .gitignore
这里是.gitignore的内容。
$ cat .gitignore
*.foo
我看到.gitignore 中的模式与 shell 中的相同模式的行为不同。在 shell 中 *.foo 仅匹配非隐藏文件,即不以句点开头的文件名。
$ echo *.foo
foo.foo
但.gitignore 中的*.foo 似乎匹配任何以.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)
我在哪里可以详细了解 .gitignore 所遵循的模式的精确定义,以便了解其行为与 shell glob 模式不同的地方和原因?
【问题讨论】:
-
这里有一个资源:git-scm.com/docs/gitignore。在某些条件下,它被完全视为外壳球。 “否则,Git 将模式视为适合 fnmatch(3) 使用的带有 FNM_PATHNAME 标志的 shell glob”(但如果没有,请阅读上面的内容)
-
@hiandbaii 在问这个问题之前,我确实阅读了该文档。但是,我不清楚有几件事。 shell 是否也使用
fnmatch(3)来处理全局模式?在那种情况下,为什么*不匹配.之前的零个字符(即隐藏文件)但 gitignore 呢?我无法在gitignore文档中找到解释这一点的确切部分。