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

Re: Bug: git add does not process gitignore properly

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jun 24, 2023, 10:13 UTC
Message-ID
<d748b4bb-6be2-4936-04d0-f0edcf228dfb@gmail.com>
In-Reply-To
<CAPig+cQ1qzO5txhZhki4UrvLBThdgo-aknBmEkNSjFhR9WXLRg@mail.gmail.com>
On 23/06/2023 23:07, Eric Sunshine wrote:
Show 29 quoted lines
> On Thu, Jun 22, 2023 at 3:56 PM David C Black <david.black@doulos.com> wrote:
>> Sitting at the rood of my working directory I attempted to add a file to the git repository with:
>>> git add extern/bin/build
>>
>> The repository had the following .gitignore file contents:
>>> /extern/
>>> !/extern/bin/
>>> !/extern/ABOUT.md
>>
>> I received an error message:
>>> The following paths are ignored by one of your .gitignore files:
>>> extern
>>> hint: Use -f if you really want to add them.
>>
>> By negating entries in the /extern/bin/ directory, I did not expect an error
>> message. Of course adding -f made it work, but I think it does not match the
>> described behavior for this tool.
> 
> This appears to be working as documented. From the gitginore(5) man page:
> 
>      An optional prefix "!" which negates the pattern; any matching
>      file excluded by a previous pattern will become included again. It
>      is not possible to re-include a file if a parent directory of that
>      file is excluded.
> 
> In your .gitignore file, /extern/ is ignored, which means that the
> subsequent "!/extern/.../" lines are ineffectual. So, as far as Git is
> concerned, /extern/bin/build is indeed ignored, thus its refusal
> without --force.
I think the usual way around this is to use patterns like
	/extern/*
	!/extern/bin/
	!/extern/ABOUT.md
see the example on the gitignore man page.
Best Wishes
Phillip
Previous: Eric SunshineNext: Junio C Hamano
Message 3 of 4 in “Bug: git add does not process gitignore properly”
  1. David C BlackJun 22, 2023
  2. Eric SunshineJun 23, 2023
  3. Phillip WoodJun 24, 2023
  4. Junio C HamanoJun 24, 2023

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.