a pattern ‘doc/frotz/’ matches ‘doc/frotz’ directory, but not ‘a/doc/frotz’ directory; however ‘frotz/’ matches ‘frotz’ and ‘a/frotz’ that is a directory.
Theset two patterns look quite the same, but why the latter matches both while the former one only matches one case?
The documentation of .gitignore
says:
If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.
Whenever you have a slash somewhere (but disregarding one at the end), then the pattern matches only starting at the directory where the .gitignore
is located, but not in lower directories.
In your case, the directory a/doc/frotz
does not start with the pattern doc/frotz
, so it does not match. Your second pattern, frotz
is not anchored in this way, and so does match.