[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] trouble with .gitignore patterns



In <[🔎] 87aaj0vceg.fsf@turtle.gmx.de>, Sven Joachim wrote:
>On 2011-01-16 20:58 +0100, Boyd Stephen Smith Jr. wrote:
>> In <[🔎] 20110116160216.GA6914@think.homelan>, Andrei Popescu wrote:
>>>$ git init
>>>Initialized empty Git repository in /home/amp/Download/gitest/.git/
>>>$ touch dir/file3
>>>$ echo '*' > .gitignore
>>>$ git status -s
>>>$ echo '!file1' >> .gitignore
>>>$ echo '!dir/' >> .gitignore
>>>$ git status -s
>>>?? file1
>>>$
>>>
>>>Why is 'dir' still ignored?
>>>
>> Looks like a bug to me.  It is at least an undocumented feature.
>
>The FAQ mentions¹ that you cannot add empty directories in git, and the
>'*' in .gitignore means that no _files_ below dir/ will be added.

!dir/ doesn't just match a directory.  Per the gitignore(5) manpage:
       ·   An optional prefix !  which negates the pattern; any matching file
           excluded by a previous pattern will become included again. If a
           negated pattern matches, this will override lower precedence
           patterns sources.

       ·   If the pattern ends with a slash, it is removed for the purpose of
           the following description, but it would only find a match with a
           directory. In other words, foo/ will match a directory foo and
           paths underneath it, but will not match a regular file or a
           symbolic link foo (this is consistent with the way how pathspec
           works in general in git).

My emphasis is here: "... and paths underneath it, ..."

This means a file with:
*
!dir/
as it's contents should not cause git to ignore dir/file3, since both lines 
match that file AND the last one is a negation.
-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: