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

Re: Feature Request: gitignore recursion

From
Karsten Blees <karsten.blees@gmail.com>
Date
Oct 10, 2013, 07:59 UTC
Message-ID
<52565E6A.2020907@gmail.com>
In-Reply-To
<20131007134141.GA23026@lanh>
Show 13 quoted lines
> On Mon, Oct 07, 2013 at 07:24:11AM -0400, Jeff King wrote:
>> However, one thing I expected to work but didn't is:
>> 
>>   echo '*' >.gitignore
>>   echo '!*' >my_dir/.gitignore
>> 
>> That _does_ work for attributes, like:
>> 
>>   echo '* foo=one' >.gitattributes
>>   echo '* foo=two' >my_dir/.gitattributes
>> 
>> where the more-specific file takes precedence. It works because we keep
>> an attribute stack, and look from most-specific directory to least.
Note that this doesn't work either:
  echo '*' >.gitignore
  echo '!my_dir/*' >>.gitignore
The problem isn't that git doesn't read 'my_dir/.gitignore'. Git simply doesn't recurse into excluded directories, so patterns on excluded content have no effect.
IMO this behavior is reasonable, as there is no way to check whether a negative pattern will match within an excluded untracked directory without scanning the directory.
What about this instead?
--- 8< ---
Subject: [PATCH] gitignore.txt: clarify recursive nature of excluded directories

Additionally, precedence of negated patterns is exactly as outlined in the description, we don't need to repeat this.

Signed-off-by: Karsten Blees <blees@dcon.de>
---
 Documentation/gitignore.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index f971960..a64a65d 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -79,8 +79,9 @@ PATTERN FORMAT
 
  - An optional prefix "`!`" which negates the pattern; any
    matching file excluded by a previous pattern will become
-   included again.  If a negated pattern matches, this will
-   override lower precedence patterns sources.
+   included again. It is not possible to re-include a file if a parent
+   directory of that file is excluded (i.e. excluding a directory
+   will recursively and irrevocably exclude the entire content).
    Put a backslash ("`\`") in front of the first "`!`" for patterns
    that begin with a literal "`!`", for example, "`\!important!.txt`".
 
-- 
1.8.4.msysgit.1
Previous: Duy NguyenNext: Jeff King
Message 5 of 7 in “Feature Request: gitignore recursion”
  1. AJOct 6, 2013
  2. Duy NguyenOct 7, 2013
  3. Jeff KingOct 7, 2013
  4. Duy NguyenOct 7, 2013
  5. Karsten BleesOct 10, 2013
  6. Jeff KingOct 10, 2013
  7. Karsten BleesOct 10, 2013

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.