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

Re: git-add ignores exclude markers for ignored files

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 20, 2026, 20:46 UTC
Message-ID
<xmqqwm1cxbad.fsf@gitster.g>
In-Reply-To
<xmqqtsz9o3cn.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 37 quoted lines
> "Rahn, René" <Rene.Rahn@pfizer.com> writes:
>
>> Steps to reproduce:
>>
>> mkdir git-add-test
>> cd git-add-test
>> git init
>> touch .gitignore
>> echo “ignored.txt” >>.gitignore
>> touch ignored.txt
>> git add --“:(exclude)ignored.txt”
>> 
>> Expected behavior:
>> 
>> The git add command recognizes that the file ignored.txt is
>> already excluded despite of it being ignored by some gitignore and
>> thus does not check if it is ignored or not. It simply will not be
>> added.  Note forcing git-add will do the trick, but this could
>> also have side effects for some files that are ignored but not
>> present in the list of excluded files.  Hence, this can’t be the
>> right solution.
>
> It is not quite clear what you want to see.  The command would not
> add ignored.text even if you give ":(exclude)ignored.txt" from the
> command line, would it?
>
> This may be an ancient regression when e1b8c7bd (dir: remove struct
> path_simplify, 2017-01-04) was rewritten exclude_matches_pathspec()
> function, which was written in 29209cbe (dir: fix COLLECT_IGNORED on
> excluded prefixes, 2010-03-11), back in the days before ":(exclude)"
> and other pathspec magic was even invented.
>
> Perhaps try this patch?
>
> I have no idea what the ramifications of the change is, though.
> There may be unintended fallouts in some distant corner, even though
> it does not seem to break any existing tests.

As I haven't heard from anybody if this patch improves the reported situation or there are unintended behaviour changes that degrades the system, I'll drop this topic from 'seen' soonish, as this topic is not exactly my itch. That does not mean that it is unwelcome if motivated others pick up the patch and polish it to bring it to the finish line. Anybody doing so should consult the original discussion thread [*].

Thanks.
[Reference]
* https://lore.kernel.org/git/xmqqtsz9o3cn.fsf@gitster.g/
Previous: Junio C Hamano
Message 4 of 4 in “git-add ignores exclude markers for ignored files”
  1. rahnNov 4, 2025
  2. Junio C HamanoNov 4, 2025
  3. Junio C HamanoNov 5, 2025
  4. Junio C HamanoJan 20, 2026

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.