git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/docs] make slash-rules more readable

From
Dr. Adam Nielsen <admin@in-ici.net>
Date
Apr 5, 2019, 20:00 UTC
Message-ID
<20190405200045.10063-1-admin@in-ici.net>
From: Adam Nielsen <admin@in-ici.net>
gitignore.txt: make slash-rules more readable

Remove the addition `it is removed for the purpose of the following description` and make clear in which situations a trailing slash is used or not. Increase readability and make all paragraphs valid, even if they are not read in strict order. Replace `otherwise` with the the concrete pattern that is considered in the paragraph to avoid confusion. Add simple examples to point out the significant difference between using or not using a trailing slash.

Signed-off-by: Adam J. N. Nielsen <info@drnielsen.de>
---
 Documentation/gitignore.txt | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 1c94f08ff4..c6720b0ac4 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -89,22 +89,25 @@ PATTERN FORMAT
    Put a backslash ("`\`") in front of the first "`!`" for patterns
    that begin with a literal "`!`", for example, "`\!important!.txt`".
 
- - If the pattern ends with a slash, it is removed for the
-   purpose of the following description, but it would only find
+ - If the pattern ends with a slash "`/`", it would only find
    a match with a directory.  In other words, `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).
 
- - 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).
+ - If the pattern contains no slash "`/`" other then a trailing slash,
+   then the pattern will match in all directories. In other words,
+   `foo/` will match `/bar/foo/` and `foo` will match `/bar/bar/foo`.
 
- - Otherwise, Git treats the pattern as a shell glob: "`*`" matches
-   anything except "`/`", "`?`" matches any one character except "`/`"
-   and "`[]`" matches one character in a selected range. See
+ - If the pattern contains a slash "`/`" other then a trailing slash, then
+   the pattern is always considered from the `.gitignore` file location.
+   In other words, `foo/bar` will match `/foo/bar` but not `/bar/foo/bar`.
+
+ - The character "`*`" matches anything except a non trailing slash "`/`".
+   For example, "foo/*" matches "foo/test.json" and "foo/bar/"
+   but not "foo/bar/test.json".
+   The character "`?`" matches any one character except "`/`".
+   The character "`[]`" matches one character in a selected range. See
    fnmatch(3) and the FNM_PATHNAME flag for a more detailed
    description.
 
-- 
2.17.1
Next: Junio C Hamano
Message 1 of 8 in “make slash-rules more readable”
  1. make slash-rules more readableDr. Adam Nielsen, Apr 5, 2019
  2. Junio C HamanoApr 8, 2019
  3. Dr. Adam NielsenApr 8, 2019
  4. Junio C HamanoApr 9, 2019
  5. Dr. Adam NielsenApr 9, 2019
  6. Junio C HamanoApr 9, 2019
  7. Dr. Adam NielsenApr 10, 2019
  8. Dr. Adam NielsenApr 17, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.