在哪里指定了 gitignore 递归行为?

Where is gitignore recursive behavior specified?

参考the online docs:

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',任何名为 'foo' 的文件或目录将仅相对于 .gitignore 文件被忽略。我没有阅读任何解释其递归行为的内容。 Shell glob(来自 what I read 和经验)不是递归的。

下面进一步解释双星号:

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,但递归行为仍然是隐式的。

像“foo”这样的规则的递归性质源于获取和应用这些规则的方式:

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”文件。