Browse Source

gitignore.txt: make slash-rules more readable

Renew paragraphs relevant for pattern with slash.
Aim to make it more clear and to avoid possible
pitfalls for the reader. Add some examples.

Signed-off-by: Dr. Adam Nielsen <admin@in-ici.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Dr. Adam Nielsen 6 years ago committed by Junio C Hamano
parent
commit
1a58bad014
  1. 66
      Documentation/gitignore.txt

66
Documentation/gitignore.txt

@ -89,28 +89,28 @@ PATTERN FORMAT
Put a backslash ("`\`") in front of the first "`!`" for patterns Put a backslash ("`\`") in front of the first "`!`" for patterns
that begin with a literal "`!`", for example, "`\!important!.txt`". that begin with a literal "`!`", for example, "`\!important!.txt`".


- If the pattern ends with a slash, it is removed for the - The slash '/' is used as the directory separator. Separators may
purpose of the following description, but it would only find occur at the beginning, middle or end of the `.gitignore` search pattern.
a match with a directory. In other words, `foo/` will match a
directory `foo` and paths underneath it, but will not match a - If there is a separator at the beginning or middle (or both) of the
regular file or a symbolic link `foo` (this is consistent pattern, then the pattern is relative to the directory level of the
with the way how pathspec works in general in Git). particular `.gitignore` file itself. Otherwise the pattern may also

match at any level below the `.gitignore` level.
- If the pattern does not contain a slash '/', Git treats it as
a shell glob pattern and checks for a match against the - If there is a separator at the end of the pattern then the pattern
pathname relative to the location of the `.gitignore` file will only match directories, otherwise the pattern can match both
(relative to the toplevel of the work tree if not from a files and directories.
`.gitignore` file).

- For example, a pattern `doc/frotz/` matches `doc/frotz` directory,
- Otherwise, Git treats the pattern as a shell glob: "`*`" matches but not `a/doc/frotz` directory; however `frotz/` matches `frotz`
anything except "`/`", "`?`" matches any one character except "`/`" and `a/frotz` that is a directory (all paths are relative from
and "`[]`" matches one character in a selected range. See the `.gitignore` file).
fnmatch(3) and the FNM_PATHNAME flag for a more detailed
description. - An asterisk "`*`" matches anything except a slash.

The character "`?`" matches any one character except "`/`".
- A leading slash matches the beginning of the pathname. The range notation, e.g. `[a-zA-Z]`, can be used to match
For example, "/{asterisk}.c" matches "cat-file.c" but not one of the characters in a range. See fnmatch(3) and the
"mozilla-sha1/sha1.c". FNM_PATHNAME flag for a more detailed description.


Two consecutive asterisks ("`**`") in patterns matched against Two consecutive asterisks ("`**`") in patterns matched against
full pathname may have special meaning: full pathname may have special meaning:
@ -144,6 +144,28 @@ To stop tracking a file that is currently tracked, use
EXAMPLES EXAMPLES
-------- --------


- The pattern `hello.*` matches any file or folder
whose name begins with `hello`. If one wants to restrict
this only to the directory and not in its subdirectories,
one can prepend the pattern with a slash, i.e. `/hello.*`;
the pattern now matches `hello.txt`, `hello.c` but not
`a/hello.java`.

- The pattern `foo/` will match a directory `foo` and
paths underneath it, but will not match a regular file
or a symbolic link `foo` (this is consistent with the
way how pathspec works in general in Git)

- The pattern `doc/frotz` and `/doc/frotz` have the same effect
in any `.gitignore` file. In other words, a leading slash
is not relevant if there is already a middle slash in
the pattern.

- The pattern "foo/*", matches "foo/test.json"
(a regular file), "foo/bar" (a directory), but it does not match
"foo/bar/hello.c" (a regular file), as the asterisk in the
pattern does not match "bar/hello.c" which has a slash in it.

-------------------------------------------------------------- --------------------------------------------------------------
$ git status $ git status
[...] [...]

Loading…
Cancel
Save