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

Re: gitignore: negating path patterns

From
Michael J Gruber <michaeljgruber+gmane@fastmail.fm>
Date
May 23, 2008, 07:52 UTC
Message-ID
<g15t3j$eoa$1@ger.gmane.org>
In-Reply-To
<5BBB5607-DF95-4C06-BE6C-C3D7AF475FBF@sb.org>
Kevin Ballard venit, vidit, dixit 23.05.2008 02:23:
Show 17 quoted lines
> On May 21, 2008, at 7:52 AM, Michael J Gruber wrote:
> 
>> Hi there
>>
>> It seems that negating path patterns in gitignore doesn't work, or I
>> don't understand it (or both). With the attached script, git status
>> (1.5.5.1) reports "dir/a" as new and "dir/b" as untracked. I would
>> rather expect it to report "dir/c" as untracked also.
>>
>> It seems that "!b" matches to include "dir/b" (reverting the exclusion
>> "*" as expected), whereas "!dir/" does not match to include "dir/c".
>>
>> What's going on here?
> 
> "dir/" will not match anything, because paths are compared without  
> trailing slashes. Try "!dir".
> 

I am sorry, but this is plain wrong, at least if "man gitignore" is right (see below). "!dir" would match files whose name (pathname without leading directory name) matches "dir" (i.e.: is dir) and exclude those from exclusion (include them).

Also, replacing "!dir/" by "!dir" in my test script does not change the result. In fact, for "!dir" the result is as expected and documented, just for "!dir/" I would expect something else.

So, thanks for trying to help, although reading the manual or testing your advice before would be appreciated even more. ;)

Michael
 From man gitignore:

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).

Previous: Kevin BallardNext: Kevin Ballard
Message 3 of 5 in “gitignore: negating path patterns”
  1. Michael J GruberMay 21, 2008
  2. Kevin BallardMay 23, 2008
  3. Michael J GruberMay 23, 2008
  4. Kevin BallardMay 23, 2008
  5. Michael J GruberMay 26, 2008

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.