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

Gitignore documentation

From
MRMaris Razvan <razvan.alex.maris@gmail.com>
Date
Jan 12, 2019, 20:16 UTC
Message-ID
<CALZbgSQti+t2dA4nm+DCDGxQjsvNJy3UDdqAya16v+Mv5O4Xdw@mail.gmail.com>
Hello,

I was reading the gitignore documentation (https://git-scm.com/docs/gitignore), especially the following paragraph:

         "If the pattern does not contain a slash /, Git treats it as
a shell glob pattern and checks for a match against the pathname
relative to the location of the .gitignore file (relative to the
toplevel of the work tree if not from a .gitignore file)."

From that paragraph I understand that if I have the following directory structure:

        .gitignore
        a
            f

(the root of the repository contains the file .gitignore and the folder a, while the file f is inside folder a) where the file .gitignore contains only the pattern f, when file "f" is tested whether it should be ignored or not, the pattern f in .gitignore is matched against the "pathname relative to the location of the .gitignore file" (which is a/f). Because "f" (the pattern) does not match "a/f" (the pathname relative to the location of .gitignore), the file "f" should not be ignored. However, if I test this scenario, git ignores the file (this behaviour is consistent with the examples from the rest of the documentation and other explanations on the internet).

I looked at the history of the "Documentation/gitignore.txt" file on the github repository and I saw that initially the paragraph looked like this:

        "If the pattern does not contain a slash '/', git treats it as
a shell glob pattern and checks for a match against the pathname
without leading directories."
This old version of the paragraph is consistent with git's current behaviour.

Then I saw the following commit https://github.com/git/git/commit/81c13fde379c46cad6b6e4a03ed7ee4f686c030f#diff-7fea460d44f92f185e7add8aa5620305, which changed that paragraph to the current version. However, I cannot see how the two wordings (the original one and the current one) are the same.

I would really appreciate if someone could explain how to read the current version of the paragraph such that it is consistent with git's behaviour.

Thank you, Razvan Maris

Next: Junio C Hamano
Message 1 of 5 in “Gitignore documentation”
  1. Maris RazvanJan 12, 2019
  2. Junio C HamanoJan 14, 2019
  3. Jonathan NiederJan 14, 2019
  4. Junio C HamanoJan 14, 2019
  5. Duy NguyenJan 15, 2019

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.