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

Re: gitignore broken in git 1.7.0.1: slash checks leading dirs

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 5, 2010, 15:12 UTC
Message-ID
<20100305151248.GA24748@progeny.tock>
In-Reply-To
<4B90C974.2050405@viscovery.net>
Johannes Sixt wrote:
> Jiri Slaby schrieb:
Show 14 quoted lines
>> having 'linux' line in .gitignore makes 'include/linux/vga_switcheroo.h'
>> to be ignored
>
> That's the behavior that I would expect.
>
>> though the documentation says:
>> ***
>> If the pattern does not contain a slash /, git treats it as a shell
>> glob pattern and checks for a match against the pathname without
>> leading directories.
>> ***
>
> and this citation confirms my expectation. Note that it says "pathname",
> not "filename". 'include/linux' is a "pathname".

It would be more precise to say this citation does not have much to do with it. 'include/linux' contains a slash, so that paragraph does not describe what it means.

The next paragraph is more on point:
 · Otherwise, git treats the pattern as a shell glob suitable for
   consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the
   pattern will not match a / in the pathname. For example,
   "Documentation/*.html" matches "Documentation/git.html" but not
   "Documentation/ppc/ppc.html". A leading slash matches the beginning of
   the pathname; for example, "/*.c" matches "cat-file.c" but not
   "mozilla-sha1/sha1.c".

The relevant sentence is the last one, and I can see how the length of the paragraph might be daunting. Maybe splitting it up would help?

 · Otherwise, git treats the pattern as a shell glob suitable for
   consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the
   pattern will not match a / in the pathname. For example,
   "Documentation/*.html" matches "Documentation/git.html" and
   "tools/perf/Documentation/perf-diff.html" but not
   "Documentation/ppc/ppc.html".
 · A leading slash matches the beginning of the pathname; for example,
   "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
Not sure.
Jonathan
-- %< --
Subject: gitignore.5: Clarify that path matches are not anchored
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/gitignore.txt |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 98c459d..fa15422 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -89,10 +89,13 @@ Patterns have the following format:
    for consumption by fnmatch(3) with the FNM_PATHNAME flag:
    wildcards in the pattern will not match a / in the pathname.
    For example, "Documentation/\*.html" matches
-   "Documentation/git.html" but not
-   "Documentation/ppc/ppc.html".  A leading slash matches the
-   beginning of the pathname; for example, "/*.c" matches
-   "cat-file.c" but not "mozilla-sha1/sha1.c".
+   "Documentation/git.html" and
+   "tools/perf/Documentation/perf-diff.html" but not
+   "Documentation/ppc/ppc.html".
+
+ - A leading slash matches the beginning of the pathname;
+   for example, "/*.c" matches "cat-file.c" but not
+   "mozilla-sha1/sha1.c".
 
 An example:
 
-- 
1.7.0
Previous: Jiri SlabyNext: Jonathan Nieder
Message 15 of 19 in “gitignore broken in git 1.7.0.1: slash checks leading dirs”
  1. Jiri SlabyMar 5, 2010
  2. Johannes SixtMar 5, 2010
  3. Jiri SlabyMar 5, 2010
  4. Johannes SixtMar 5, 2010
  5. 1/1 gitignore: do not ignore include/linux/Jiri Slaby, Mar 5, 2010
  6. Jakub NarebskiMar 5, 2010
  7. Jiri SlabyMar 5, 2010
  8. David RientjesMar 10, 2010
  9. Américo WangMar 10, 2010
  10. David RientjesMar 10, 2010
  11. Américo WangMar 8, 2010
  12. Jiri SlabyMar 5, 2010
  13. Jonathan NiederMar 5, 2010
  14. Jiri SlabyMar 5, 2010
  15. Jonathan NiederMar 5, 2010
  16. Jonathan NiederMar 5, 2010
  17. Johannes SixtMar 5, 2010
  18. gitignore.5: Clarify matching rulesJonathan Nieder, Mar 5, 2010
  19. Junio C HamanoMar 5, 2010

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.