# [Feature Request] Negated non-wildcard patterns in excluded directories in `.gitignore`

1 messages from 2025-03-04 to 2025-03-04. Participants: Joschua Kesper.
Thread: https://gitlist.dev/t/63060

## Joschua Kesper, 2025-03-04 19:17

Subject: [Feature Request] Negated non-wildcard patterns in excluded directories in `.gitignore`
Message-ID: <43b26c9b-fd08-4a21-8371-9fd53f54694a@tu-dortmund.de>
URL: https://gitlist.dev/e/43b26c9b-fd08-4a21-8371-9fd53f54694a%40tu-dortmund.de

```
Dear Git Community,

I have the somewhat unusual use-case and use negated patterns somewhat
regularly. If I have a path `foo/bar/baz` which I want to track with
git, but don't want any other files in `foo`. I would have to write the
following in the `.gitignore`:

	foo/*
	!foo/bar
	foo/bar/*
	!foo/bar/baz

Instead of the simpler:

	foo
	!foo/bar/baz

In `gitignore(5)` you mention:

 > It is not possible to re-include a file if a parent directory of that
 > file is excluded. Git doesn’t list excluded directories for
 > performance reasons, so any patterns on contained files have no
 > effect, no matter where they are defined.

This is (I think) due to patterns like `!*.c`.
So I propose changing it so exact-matching pattern parts like `foo` or
`bar` to always work. This could be done by expanding it to the form
mentioned above.

This change wouldn't affect performance I would argue, since writing
`!foo/bar/baz` is pretty unambiguous in what the user intended.
Depending on the implementation it may even improve performance,
since we would only require listing of `foo/bar/baz` and not all of it's
parents (though I am simply guessing the implementation for
`<something>/*` here).

Joschua

```
