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

[PATCH 1/4] Documentation/gitignore: "foo/" patterns match directories, not files under them

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

The gitignore(5) manpage says that "foo/" will match a directory foo and paths underneath it. But that is completely false: as Johannes Sixt likes to remind us, patterns with a trailing '/' match the named directory, not files under that directory. For example, the following .gitignore file

	/build/
	!/build/tests/results

does not un-ignore build/tests/results since it was never ignored in the first place; and commands like "git status" will not notice changes to build/tests/results because git doesn't enter the (ignored) build/ directory.

Correct the manual to just say that "foo/" matches the directory "foo", and make the wording a little clearer in other ways while at it.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/gitignore.txt |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 2e7328b8..5b070bf0 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -72,12 +72,14 @@ PATTERN FORMAT
    included again.  If a negated pattern matches, this will
    override lower precedence patterns sources.
 
- - If the pattern ends with a slash, it is removed for the
-   purpose of the following description, but 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 ends with a slash, it will only match
+   directories.  In other words, `foo/` will match a
+   directory `foo` but will not match a regular file or a
+   symbolic link `foo` (this is consistent with the way
+   pathspecs work in general in git).
++
+The trailing slash is removed before applying the remaining
+rules.
 
  - If the pattern does not contain a slash '/', git treats it as
    a shell glob pattern and checks for a match against the
-- 
1.7.8.rc0
Previous: Jonathan NiederNext: Nguyen Thai Ngoc Duy
Message 2 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.