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

Re: Gitignore file exceptions are not applied to untarcked files

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 29, 2016, 18:31 UTC
Message-ID
<xmqqd1skjkyp.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CAMrYpX5n1LHBnr+bMhV=8Eu1K2npKctVZrHxJcStBhSVC70OBg@mail.gmail.com>
Assen Totin <assen.totin@gmail.com> writes:
Show 5 quoted lines
> I'm not sure if the described issue is a bug or a feature; if it is the
> latter, please, excuse the report.
>
> I'm dealing with git 1.7.12.4. If this has been addressed in the later
> issue, please, point me so.

That is a bit too ancient version, so I am not sure how it behaved back then.

Show 12 quoted lines
> I'm only interested in /tracked_dir/.../config files. My .gitignore is as
> follows:
>
> # Ignore everything first
> *
> # Do not ignore tracked files
> !/tracked_dir/*/config
> # Don't ignore .gitignore
> !.gitignore
>
> This works fine until a new directory with a config file is created inside
> /tracked_dir:

I am not sure if that is "working fine". First, aren't these 'config' files tracked? "!/tracked_dir/*/config" or whatever you have in the gitignore files have no effect on what is already tracked.

That is, if you replace your .gitignore with a single line,
	# ignore everything
        *

your /tracked_dir/foo/config that is already in the index (i.e. "git ls-files tracked_dir/foo/config" would show it) would not be ignored.

> Is it because the exclusion pattern is never
> applied to untracked files? Or is it because the directory new_subdir is
> itself untracked?

So my suspicion is that (1) you do see tracked_dir/subdir1/config is not ignored not because of any of your !tracked_dir/*/config lines but because tracked_dir/subdir1/config is already in the index, and (2) your tracked_dir/new_subdir/config is shown as ignored because it is not tracked yet, and '*' tells Git that new_subdir is ignored.

By the way, this area did have a recent regression at v2.7.0, to which a fix is percolating down to the v2.7.x maintenance track.

Previous: Assen TotinNext: Anatoly Borodin
Message 2 of 3 in “Gitignore file exceptions are not applied to untarcked files”
  1. Assen TotinJan 29, 2016
  2. Junio C HamanoJan 29, 2016
  3. Anatoly BorodinJan 29, 2016

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.