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

Re: Relative paths don't work in .gitignore as would be expected.

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 3, 2015, 20:11 UTC
Message-ID
<xmqqtwz2rc06.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CALbm-Ea7X3dDrMUw0sDhWf0sg+zs7oRUkRD+aPzD9fHqB=ZuWQ@mail.gmail.com>
Stefan Beller <stefanbeller@gmail.com> writes:
Show 21 quoted lines
> 2015-02-02 11:15 GMT-08:00 Junio C Hamano <gitster@pobox.com>:
>
>> Isn't gitignore(5) documentation reasonably clear?
>> ...
>>  - A leading slash matches the beginning of the pathname. For
>>    example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
>>
>>> That's true, though you'd never (barely?) git version control an entire
>>> file system?
>>
>> When you have the entire file system under /.git, "/var/" still
>> would be the right way to spell a pattern to match ...
>> ... and lives in the root level of the filesystem (because of the
>> leading '/' anchors
>> the pattern to the same level as the file the pattern appears in,
>> i.e. /.gitignore) and no other place.
>
> ... Now I realize git treats the repository
> root literally as the root and hence absolute paths starting with "/"
> make totally sense inside git as the world stops for git outside its
> work directory.

Only when the pattern appears in .gitignore at the top-level of the project, you can say: "/*.js" matches files with ".js" suffix at the root level of the project because '/' means 'root'.

But that explanation breaks down for "t/.gitignore" that has entries like "/.prove". It is not excluding ".prove" at the top-level of the project. It is excluding those that appear at the same level as that ignore file in question lives in, i.e. the "t/" directory. It excludes "t/.prove", it excludes neither ".prove" at the top-level nor "t/tt/ttt/.prove".

In hindsight, using '/' prefix as a way to anchor the patter to the same directory the .gitignore file appears in was suboptimal, exactly because it would invite the above reaction. But I do not know if using "./" as the prefix to denote the same thing would have been better.

Previous: Stefan Beller
Message 5 of 5 in “Relative paths don't work in .gitignore as would be expected.”
  1. /#!/JoePeaFeb 1, 2015
  2. Stefan BellerFeb 2, 2015
  3. Junio C HamanoFeb 2, 2015
  4. Stefan BellerFeb 3, 2015
  5. Junio C HamanoFeb 3, 2015

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.