Where is gitignore recursive behavior specified?

2019-05-19 01:15发布

Referring to 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).

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:

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"

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

1条回答
Ridiculous、
2楼-- · 2019-05-19 01:51

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

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.

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

查看更多
登录 后发表回答