From: Phillip Wood <phillip.wood123@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>,
David C Black <david.black@doulos.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Bug: git add does not process gitignore properly
Date: Sat, 24 Jun 2023 11:13:22 +0100 [thread overview]
Message-ID: <d748b4bb-6be2-4936-04d0-f0edcf228dfb@gmail.com> (raw)
In-Reply-To: <CAPig+cQ1qzO5txhZhki4UrvLBThdgo-aknBmEkNSjFhR9WXLRg@mail.gmail.com>
On 23/06/2023 23:07, Eric Sunshine wrote:
> 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
next prev parent reply other threads:[~2023-06-24 10:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 19:38 Bug: git add does not process gitignore properly David C Black
2023-06-23 22:07 ` Eric Sunshine
2023-06-24 10:13 ` Phillip Wood [this message]
2023-06-24 22:19 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d748b4bb-6be2-4936-04d0-f0edcf228dfb@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=david.black@doulos.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).