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

Re: gitignore: how to exclude a directory tree from being ignored

From
PPeter <vmail@mycircuit.org>
Date
Oct 1, 2009, 13:00 UTC
Message-ID
<4AC4A7EF.9030002@mycircuit.org>
In-Reply-To
<4AC4A310.8000507@viscovery.net>
Johannes Sixt wrote:
Show 36 quoted lines
> Peter schrieb:
>   
>> Hi
>> I want to exclude binaries except in a dir tree that I do not control.
>>
>> In .gitignore  I have:
>>
>>
>> I would expect that all *.exe and *.o are ignored except those somewhere
>> in the vendor dir tree.
>> However, the *.exe and *.o in the vendor dir tree are also ignored.
>>     
>
> This works for me:
>
>  *.exe
>  *.o
>  !vendor/*.exe
>  !vendor/*.o
>
> Note that git-status does not descend into directories from which no files
> are tracked. Therefore, this will work only after you have git-added at
> least one file from vendor/.
>
> git ls-files -o --exclude-standard does descend into the directory.
>
> Furthermore, the !vendor/*.exe patterns are not recursive. Perhaps it is
> easier for you to have a separate vendor/.gitignore that has:
>
>  !*.exe
>  !*.o
>
> These _are_ recursive.
>
> -- Hannes
>   
Thanks a lot, that clarifies the problem for me. As far as I understand now:
1) I can't have just one .gitignore file in the root dir, if I want to 
_recursively_ inverse the exclude pattern for a sub dir tree.
In this case, I have to put individual .gitignore files in the sub trees 
I want to re-include.
2) In order to see what will be staged, I have to use the :
git ls-files -o --exclude-standard
instead of :
git ls-files -o -i --exclude-from=.gitignore
because the latter won't consider .gitignore patterns in subtree
Peter
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 7 in “gitignore: how to exclude a directory tree from being ignored”
  1. PeterOct 1, 2009
  2. Johannes SixtOct 1, 2009
  3. PeterOct 1, 2009
  4. Johannes SixtOct 1, 2009
  5. PeterOct 1, 2009
  6. Johannes SixtOct 1, 2009
  7. PeterOct 1, 2009

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.