哪里指定gitignore递归行为? [英] Where is gitignore recursive behavior specified?

查看:104
本文介绍了哪里指定gitignore递归行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考在线文档:

如果该模式不包含斜杠/,则Git会将其视为shell glob模式,并检查相对于.gitignore文件位置的路径名是否匹配(如果不是,则相对于工作树的顶层) .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).

对我来说,该文档说,给定模式"foo",仅相对于.gitignore文件,将忽略任何名为"foo"的文件或目录.我没有阅读任何解释其递归行为的内容. Shell全局变量(来自我读过的内容)不是递归的

To me, this documentation says that given a pattern 'foo', any file or directory named 'foo' will be ignored only relative to the .gitignore file. I don't read anything explaining its recursive behavior. Shell globs (from what I read and experience) are not recursive.

现在在其下方进一步说明了双星号:

Now further below it explains the double asterisk:

前导"**"后跟斜杠表示在所有目录中均匹配.例如,"**/foo"在任何位置都匹配文件或目录"foo",与模式"foo"相同

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo"

所以是的,文档中有一个示例说明**/foo等于foo,但是递归行为仍然是隐式的.

so yes there is an example in the docs explaining that **/foo is equal to foo, but the recursive behavior remains implicit.

推荐答案

"foo"之类的规则的递归性质是从获取和应用这些规则的方式中得出的:

The recursive nature of a rule like "foo" is derived from the way those rules are fetched and applied:

从与路径相同的目录中或任何父目录中的.gitignore文件读取的模式,其中较高级别文件(直到工作树的顶层)中的模式为被较低级别文件中的文件覆盖,直到包含该文件的目录.

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.

因此,即使.gitignore下有多个子目录,规则"foo"仍将适用于在该子文件夹中找到的任何"foo"文件.

So even multiple sub-directories below a .gitignore, the rule "foo" will still apply to any "foo" file found in said sub-folder.

这篇关于哪里指定gitignore递归行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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