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

[PATCH 3/4] Documentation: unanchored gitignore patterns match basename

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 7, 2011, 08:09 UTC
Message-ID
<20111107080926.GC30486@elie.hsd1.il.comcast.net>
In-Reply-To
<20111107080449.GA30448@elie.hsd1.il.comcast.net>

The rule described by v1.7.1.1~31^2 (gitignore.5: Clarify matching rules, 2010-03-05) is just false: simple gitignore patterns without a slash like "foo" and "cscope*" have always matched files in all directories, not just the toplevel, and a question mark cannot be used to match the slash separating path components.

For example:
	foo/ - matches directories named "foo" throughout the tree
	Documentation?foo - does not match Documentation/foo
Reported-by: Y.G. <yamomo1@hotmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/gitignore.txt |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index c7c948dd..e5715a27 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -80,18 +80,19 @@ PATTERN FORMAT
 
  - If the pattern does not contain a slash '/' at the beginning
    or in the middle, git treats it as a shell glob pattern and
-   matches the entire pathname including slashes, relative to the
-   location of the `.gitignore` file (or relative to the toplevel
-   of the work tree if the pattern is not from a `.gitignore`
-   file), against it.
-   For example, "{asterisk}.html" matches HTML files in the
-   directory containing the `.gitignore` file and in its
-   subdirectories.
+   checks if the pathname with leading path components
+   removed matches it.
+   For example, "x{asterisk}.html" matches HTML files whose
+   filename begins with an "x" in the directory containing
+   the `.gitignore` file and in its subdirectories.
 
  - If the pattern contains a slash '/' at the beginning or in the
    middle, git imitates the behavior of fnmatch(3) with the
-   FNM_PATHNAME flag: wildcards in the pattern will not match a /
-   in the pathname.
+   FNM_PATHNAME flag.  The pattern is used to match the entire
+   pathname, relative to the location of the `.gitignore` file
+   (or relative to the toplevel of the work tree if the pattern
+   is not from a `.gitignore` file).  Wildcards in the pattern
+   do not match a / in the pathname.
    For example, "Documentation/{asterisk}.html" matches
    "Documentation/git.html" but not "Documentation/ppc/ppc.html"
    or "tools/perf/Documentation/perf.html".
-- 
1.7.8.rc0
Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 7 of 10 in “gitignore.5 clarifications”
  1. 0/5 gitignore.5 clarificationsJonathan Nieder, Nov 7, 2011
  2. 1/4 Documentation/gitignore: "foo/" patterns match directories, not files under themJonathan Nieder, Nov 7, 2011
  3. Nguyen Thai Ngoc DuyNov 7, 2011
  4. Junio C HamanoNov 7, 2011
  5. 2/4 Documentation: clarify effect of '/' in gitignore(5) patternsJonathan Nieder, Nov 7, 2011
  6. Nguyen Thai Ngoc DuyNov 7, 2011
  7. 3/4 Documentation: unanchored gitignore patterns match basenameJonathan Nieder, Nov 7, 2011
  8. Nguyen Thai Ngoc DuyNov 7, 2011
  9. 4/4 Documentation/gitignore: explain how to un-ignore part of a directoryJonathan Nieder, Nov 7, 2011
  10. Nguyen Thai Ngoc DuyNov 7, 2011

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.