# `*' gitignores and nested ignores

3 messages from 2011-03-24 to 2011-03-25. Participants: Eli Barzilay, Johannes Sixt.
Thread: https://gitlist.dev/t/26850

## Eli Barzilay, 2011-03-24 10:10

Subject: `*' gitignores and nested ignores
Message-ID: <19851.6264.179471.935771@winooski.ccs.neu.edu>
URL: https://gitlist.dev/e/19851.6264.179471.935771%40winooski.ccs.neu.edu

```
According to the man page, a .gitignore file that is deeper has higher
precedence, and a `!' line overrides lower precedence ignores.  I
tried that, and it works in cases like the last "vmlinux*" example.

But it doesn't work if the lower precedence directory has a "*"
pattern.  If the last example from the man page is changed to:

               $ cat .gitignore
               *
               $ ls arch/foo/kernel/vm*
               arch/foo/kernel/vmlinux.lds.S
               $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore

then -- IIUC -- the second ignore should work the same, but it
doesn't.  This also happens if the first pattern is "/*".

Is this a bug?


BTW, my use case is to track random stuff in a directory that has lots
of junk.  I wanted to do this by having a toplevel "/*" ignore and add
files explicitly when I want to.  But there are some directories that
should be tracked, and I was trying to achieve this effect by adding a
"!/*" pattern in them.  Is there a more convenient (or saner) way of
doing this?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

```

## Johannes Sixt, 2011-03-25 08:18

Subject: Re: `*' gitignores and nested ignores
Message-ID: <4D8C4FCF.5060900@viscovery.net>
URL: https://gitlist.dev/e/4D8C4FCF.5060900%40viscovery.net
In-Reply-To: <19851.6264.179471.935771@winooski.ccs.neu.edu>

```
Am 3/24/2011 11:10, schrieb Eli Barzilay:
> According to the man page, a .gitignore file that is deeper has higher
> precedence, and a `!' line overrides lower precedence ignores.  I
> tried that, and it works in cases like the last "vmlinux*" example.
> 
> But it doesn't work if the lower precedence directory has a "*"
> pattern.  If the last example from the man page is changed to:
> 
>                $ cat .gitignore
>                *
>                $ ls arch/foo/kernel/vm*
>                arch/foo/kernel/vmlinux.lds.S
>                $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore
> 
> then -- IIUC -- the second ignore should work the same, but it
> doesn't.  This also happens if the first pattern is "/*".
> 
> Is this a bug?

This has been discussed before, and IMNSHO, this is not a bug:

http://thread.gmane.org/gmane.comp.version-control.git/157190

-- Hannes

```

## Eli Barzilay, 2011-03-25 09:37

Subject: Re: `*' gitignores and nested ignores
Message-ID: <19852.25158.340116.57859@winooski.ccs.neu.edu>
URL: https://gitlist.dev/e/19852.25158.340116.57859%40winooski.ccs.neu.edu
In-Reply-To: <4D8C4FCF.5060900@viscovery.net>

```
An hour ago, Johannes Sixt wrote:
> Am 3/24/2011 11:10, schrieb Eli Barzilay:
> > According to the man page, a .gitignore file that is deeper has
> > higher precedence, and a `!' line overrides lower precedence
> > ignores.  I tried that, and it works in cases like the last
> > "vmlinux*" example.
> > 
> > But it doesn't work if the lower precedence directory has a "*"
> > pattern.  [...]
> > 
> > Is this a bug?
> 
> This has been discussed before, and IMNSHO, this is not a bug:
> 
> http://thread.gmane.org/gmane.comp.version-control.git/157190

To reply to what you wrote there:

> You should update your expectations to match what you got.

That kind of an answer is a thick hint that something is not
documented right.  As things stand, I don't see anything in the man
page that describes the actual algorithm that is used.  I also found a
similar weirdness now -- the man page says

  within one level of precedence, the last matching pattern decides
  the outcome

but this is not true for nested files in this case:

  *
  !foo

So some description of what's going on is needed.  Perhaps it's
exactly what Seth's suggested patch describes.


In any case, it seems possible to do something that works more as
expected.  As suggested in that thread -- scanning only directories
that have committed files would not make things slow, since the files
need to be checked anyway.  This is not even hard to describe in a man
page.  It seems like some arbitrariness that buys performance, but its
less so than the current situation.

There's also the option of scanning only .gitignore files that are
checked in, but that will probably be too confusing when the files are
created and/or modified.

Yet another alternative is to say that an ignored .gitignore file is
ignored, and making this:

  /*
  !.gitignore

an idiom for doing the slow thing in case you really want it.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

```
