@@ -89,24 +89,35 @@ PATTERN FORMAT
89
89
Put a backslash ("`\`") in front of the first "`!`" for patterns
90
90
that begin with a literal "`!`", for example, "`\!important!.txt`".
91
91
92
- - If the pattern ends with a slash, it is removed for the
93
- purpose of the following description, but it would only find
92
+ - If the pattern ends with a slash, it would only find
94
93
a match with a directory. In other words, `foo/` will match a
95
94
directory `foo` and paths underneath it, but will not match a
96
95
regular file or a symbolic link `foo` (this is consistent
97
96
with the way how pathspec works in general in Git).
98
97
99
- - If the pattern does not contain a slash '/', Git treats it as
100
- a shell glob pattern and checks for a match against the
101
- pathname relative to the location of the `.gitignore` file
102
- (relative to the toplevel of the work tree if not from a
103
- `.gitignore` file).
104
-
105
- - Otherwise, Git treats the pattern as a shell glob: "`*`" matches
106
- anything except "`/`", "`?`" matches any one character except "`/`"
107
- and "`[]`" matches one character in a selected range. See
108
- fnmatch(3) and the FNM_PATHNAME flag for a more detailed
109
- description.
98
+ - If the pattern contains no slash "`/`" (except an optional trailing slash),
99
+ the pattern is matched against all files and folders (recursively)
100
+ from the location of the `.gitignore` file.
101
+ For example, `frotz/` matches `frotz` and `a/frotz` that
102
+ is a directory (relative from the `.gitignore` file).
103
+
104
+ - A pattern that contains a non-trailing slash is matched relative to the
105
+ location of the `.gitignore` file.
106
+ For example, `doc/frotz/` matches `doc/frotz` directory, but not
107
+ `a/doc/frotz` (relative from the `.gitignore` file).
108
+ Note that the pattern `doc/frotz` and `/doc/frotz`
109
+ have the same effect in any `.gitignore` file, while `/bar` and `bar`
110
+ have not the same effect (`/bar` will not match `foo/bar`).
111
+
112
+ - An asterisk "`*`" matches anything except a slash. A
113
+ pattern "foo/*", for example, matches "foo/test.json" (a
114
+ regular file), "foo/bar" (a diretory), but it does not match
115
+ "foo/bar/hello.c" (a regular file), as the asterisk in the
116
+ pattern does not match "bar/hello.c" which has a slash in it.
117
+ The character "`?`" matches any one character except "`/`"
118
+ The range notation, e.g. `[a-zA-Z]`, can be used to match
119
+ one of the characters in a range. See fnmatch(3) and the
120
+ FNM_PATHNAME flag for a more detailed description.
110
121
111
122
- A leading slash matches the beginning of the pathname.
112
123
For example, "/{asterisk}.c" matches "cat-file.c" but not
0 commit comments