Thread (4 messages) 4 messages, 4 authors, 2023-06-24

Re: Bug: git add does not process gitignore properly

From: Eric Sunshine <hidden>
Date: 2023-06-23 22:07:50

On Thu, Jun 22, 2023 at 3:56 PM David C Black [off-list ref] wrote:
Sitting at the rood of my working directory I attempted to add a file to the git repository with:
quoted
git add extern/bin/build
The repository had the following .gitignore file contents:
quoted
/extern/
!/extern/bin/
!/extern/ABOUT.md
I received an error message:
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help