Skip to content

Commit 7965c28

Browse files
committed
Merge branch 'an/ignore-doc-update' into pu
The description about slashes in gitignore patterns (used to indicate things like "anchored to this level only" and "only matches directories") has been revamped. Almost there. cf. <[email protected]> * an/ignore-doc-update: gitignore.txt: make slash-rules more readable
2 parents 42052d9 + 8955a2d commit 7965c28

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Documentation/gitignore.txt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,35 @@ PATTERN FORMAT
8989
Put a backslash ("`\`") in front of the first "`!`" for patterns
9090
that begin with a literal "`!`", for example, "`\!important!.txt`".
9191

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
9493
a match with a directory. In other words, `foo/` will match a
9594
directory `foo` and paths underneath it, but will not match a
9695
regular file or a symbolic link `foo` (this is consistent
9796
with the way how pathspec works in general in Git).
9897

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.
110121

111122
- A leading slash matches the beginning of the pathname.
112123
For example, "/{asterisk}.c" matches "cat-file.c" but not

0 commit comments

Comments
 (0)