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

Re: Feature Request: gitignore recursion

From
Jeff King <peff@peff.net>
Date
Oct 7, 2013, 11:24 UTC
Message-ID
<20131007112411.GA5792@sigill.intra.peff.net>
In-Reply-To
<CACsJy8CHcyDrzieX1Ps3LU2UxCP+QJdv9+5BXZj9Mw2bMs5v3w@mail.gmail.com>
On Mon, Oct 07, 2013 at 05:26:17PM +0700, Nguyen Thai Ngoc Duy wrote:
Show 11 quoted lines
> On Mon, Oct 7, 2013 at 5:23 AM, AJ <alljeep@gmail.com> wrote:
> > I'm hoping to get the following feature implemented into git.
> >
> > Add the ability to recursively include using:
> > !/my_dir/**/*
> 
> You can do that since v1.8.2. Actually the pattern should be
> 
> !/my_dir/**
> 
> Checkout gitignore man page for more information.
I think that is a reasonable approach to doing what the OP wants.
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.

The directory traversal code, however, tries to avoid entering directories that are ignored. So if you have told it to ignore "my_dir", we will not even look at "my_dir/.gitignore".

This is arguably a bug, as the documentation says that more specific paths should take precedence over toplevel ones. But the optimization of pruning ignored paths is very important for performance; otherwise, we would end up enumerating entire ignored subdirectories on the off chance that they have a negative .gitignore entry buried deep inside them.

So I don't think it is worth fixing, but it might be worth mentioning in the documentation. Or is it mentioned somewhere that I missed?

-Peff
Previous: Duy NguyenNext: Duy Nguyen
Message 3 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.