V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
hustlzp
V2EX  ›  git

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

  •  
  •   hustlzp · 2014-03-17 20:02:09 +08:00 · 2677 次点击
    这是一个创建于 3694 天前的主题,其中的信息可能已经有所发展或是发生改变。
    发现在.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啊。

    不知道是我哪里理解错了还是什么的,求解惑...
    2 条回复    1970-01-01 08:00:00 +08:00
    9hills
        1
    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
        2
    123123  
       2014-03-17 22:45:25 +08:00
    意思是你要写 「/admin.py
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3767 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.