[gitignore 求解惑] admin.py 为什么会匹配到 controllers/admin.py

2014-03-17 20:02:09 +08:00
 hustlzp
发现在.gitignore中写一行:

admin.py

也会匹配到子目录下的admin.py(比如controllers/admin.py)。

于是去 http://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).

就是说规则中不带/的就按照shell glob来,即按照glob规则和相对于.gitignore的所有pathname进行匹配。但是照这样来说,应该是*admin.py匹配controllers/admin.py,而 admin.py不应该匹配上这个pathname啊。

不知道是我哪里理解错了还是什么的,求解惑...
2694 次点击
所在节点    git
2 条回复
9hills
2014-03-17 20:45:57 +08:00
Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

也就是会读上一层以及上上一层直到toplevel的.gitignore

你在controllers目录下,先读本目录的.gitignore,没有就把上一层的.gitignore读下来。。也就是说相当于你在controllers目录下的.gitignore下加了一行 admin.py
123123
2014-03-17 22:45:25 +08:00
意思是你要写 「/admin.py

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/104721

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX