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

Re: Odd .gitignore behaviour

From
BSBruce Stephens <bruce.stephens@isode.com>
Date
Nov 15, 2007, 20:15 UTC
Message-ID
<80ir43e04o.fsf@tiny.isode.net>
In-Reply-To
<alpine.LFD.0.9999.0711151044150.2786@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
[...]
Show 20 quoted lines
> So what you describe sounds wrong.
>
> But my quick test didn't actually support the behaviour you see. In this 
> situation:
>
> 	[torvalds@woody git-test]$ cat .gitignore
> 	a*
> 	[torvalds@woody git-test]$ cat subdir/.gitignore
> 	!a-ok
> 	[torvalds@woody git-test]$ find *
> 	all-files
> 	subdir
> 	subdir/a-ok
> 	[torvalds@woody git-test]$ git ls-files -o --exclude-per-directory=.gitignore
> 	.gitignore
> 	subdir/.gitignore
> 	subdir/a-ok
>
> ie we *do* show "showdir/a-ok" (but we don't show "all-files") because 
> a-ok is explicitly marked to be not ignored by a higher-priority rule.
OK, and if I say "git add subdir/a-ok" I get no error, as expected.

So extend it just a tiny bit, moving a-ok down a directory and using the negative pattern "!subsubdir/a-ok" to match:

    brs% cat .gitignore
    a*
    brs% cat subdir/.gitignore
    !subsubdir/a-ok
    brs% find *
    all-files
    subdir
    subdir/.gitignore
    subdir/subsubdir
    subdir/subsubdir/a-ok
    subdir/a-ok
    brs% git ls-files -o --exclude-per-directory=.gitignore
    .gitignore
    subdir/.gitignore
    subdir/subsubdir/a-ok
    brs% git add subdir/subsubdir/a-ok
    The following paths are ignored by one of your .gitignore files:
    subdir/subsubdir/a-ok
    Use -f if you really want to add them.
    fatal: no files added

So I think the output from git-ls-files is as expected (as I interpret the manpage and your explanation). So is git-add just using some different code?

[...]
Previous: Linus TorvaldsNext: Junio C Hamano
Message 3 of 8 in “Odd .gitignore behaviour”
  1. Bruce StephensNov 15, 2007
  2. Linus TorvaldsNov 15, 2007
  3. Bruce StephensNov 15, 2007
  4. Junio C HamanoNov 15, 2007
  5. Junio C HamanoNov 15, 2007
  6. Fix per-directory exclude handing for "git add"Junio C Hamano, Nov 16, 2007
  7. Bruce StephensNov 16, 2007
  8. Bruce StephensNov 16, 2007

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.