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, 14:48 UTC
Message-ID
<4AC4C125.10609@mycircuit.org>
In-Reply-To
<4AC4AD25.5010708@viscovery.net>
Show 8 quoted lines
>> 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.
>>     
>
> No, it's not the inversion of the pattern, but the slash (if it is not at
> the end) that makes the pattern non-recursive.
>
>   
from the gitignore manpage:
 >> 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). <<

Doesn't this mean, that if I say: vendor/ matches the directory and ( recursively ) the paths underneath it.? And, consequently: !vendor/ inverse the exclusion for vendor ( that is: include ) and everything that is contained in it ? ( This is obviously not the case, but this is what I would expect )

Show 11 quoted lines
>> In this case, I have to put individual .gitignore files in the sub trees
>> I want to re-include.
>>     
>
> If you have only the directory vendor/ with no further interesting
> subdirectories, then you can use my first suggestion. But if you have your
> *.exe and *.o distributed over several directories of different depths
> below vendor/, then it might be easier to have a separate
> vendor/.gitignore with recursive patterns (i.e. that do not contain a slash).
>
>   
This works for me ( I have indeed distributed them over several dirs )
Show 10 quoted lines
>> 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
>>     
>
> After reading the documentation, I don't know, and I won't try now ;-)
>
>   
At least it seams to work here ..
> -- Hannes
>   
Thanks !
Previous: Johannes SixtNext: Johannes Sixt
Message 5 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.