`.gitignore`文件中引导斜杠的含义 [英] Meaning of leading slash in `.gitignore` file

查看:512
本文介绍了`.gitignore`文件中引导斜杠的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在带有前导斜杠的 .gitignore 文件中放置一个模式,斜线是否指向 .gitignore 文件存在,还是它引用整个存储库的根目录?



(我发现的手册页已经仔细隐藏了这些信息。 )

这是文档文本



  • 前导斜杠匹配路径名的开头。例如,/*.c匹配cat-file.c
    ,但不匹配mozilla-sha1 / sha1.c。

这些是我的猜测:


  • 资源库 - .gitignore .gitignore
    所在的目录 - 它并不真正有用使其相对于存储库的根目录。



    对存储库根目录和一个子目录(和
    <$ c $)中的同名文件如果你使用一个 .git / c> .gitignore 在这个相同的目录中)确认这一点。

  • info / exclude 或者 core.excludesfile ,我想它是相对于版本库根目录的



    这也是(对于信息/排除)由相同的测试(两个测试都在1.7.3.4)确认。




Schnouki找到了有关此文档的正确部分(重点介绍):



  • [...]

  • 模式s从与路径相同的目录中的 .gitignore 文件中读取,或者在
    任何父目录中读取,并且在较高级别文件中具有模式(直到顶层工作树的
    )被低级文件中的文件覆盖,直到包含该文件的
    目录。 这些模式与
    的位置相匹配 .gitignore 文件。
    项目通常包含这样的 .gitignore > 文件,其中包含作为项目构建一部分生成的文件的模式。
  • [...]

  • $ b

有人可能会说这个事实可能在上面引用的后面部分再次重复,为了清晰起见。


If I put a pattern in a .gitignore file with a leading slash, does the slash refer to the directory in which the .gitignore file is located, or does it refer to the root of the whole repository?

(The man pages I have found have hidden this information carefully.)

解决方案

This is the documentation text:

  • A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

These are my guesses:

  • If you use an in-repository-.gitignore, the directory in which the .gitignore is located - it is not really useful to make it relative to the repository root.

    A short experiment with same-named files in the repository root and a subdirectory (and a .gitignore in this same directory) confirms this.

  • If you use an .git/info/exclude or core.excludesfile, I suppose it is relative to the repository root.

    Also this is (for info/exclude) confirmed by the same test (both tests on 1.7.3.4).

Schnouki found the right part of the documentation about this (emphasis mine):

  • [...]
  • 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.
  • [...]

One could say that this fact could have been repeated again at the later part quoted above, for clarity.

这篇关于`.gitignore`文件中引导斜杠的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆