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

Wrong gitignore precedence?

From
YEYohei Endo <yoheie@gmail.com>
Date
Apr 22, 2015, 06:05 UTC
Message-ID
<20150422150558.6326cb6152a306f028fb6ad3@gmail.com>
Hello All,

I read the document of gitignore (http://git-scm.com/docs/gitignore), and learned that $GIT_DIR/info/exclude has higher precedence than the file specified by core.excludesfile.

But I noticed that patterns in core.excludesfile override patterns in $GIT_DIR/info/exclude.

I tested as below:
   1. Make a new git repository for test, and move into the repository.
      $ git init testrepo
      $ cd testrepo
   2. Change core.excludesfile configuration.
      $ touch ../core_excludesfile
      $ git config core.excludesfile `realpath ../core_excludesfile`
   3. Create test~. In each step I check if the file is ignored or not.
      $ touch test~
   4. See git status. In this case I expect that test~ should not be ignored.
      $ git status --ignored
   5. Change settings in .git/info/exclude.
      $ echo '*~' > .git/info/exclude
   6. See git status. In this case I expect that test~ should be ignored.
      $ git status --ignored
   7. Change settings in .git/info/exclude and core.excludesfile.
      $ echo '*~' > ../core_excludesfile
      $ echo '!*~' > .git/info/exclude
   8. See git status. In this case I expect that test~ should not be ignored.
      $ git status --ignored
   9. Change settings in .git/info/exclude and core.excludesfile
      $ echo '!*~' > ../core_excludesfile
      $ echo '*~' > .git/info/exclude
  10. See git status. In this case I expect that test~ should be ignored.
      $ git status --ignored
Steps 4. and 6. worked as I expected, but 8. and 10. didn't.

I read the source code of Git, and found out the point that seems to cause the problem.

In dir.c, setup_standard_excludes() adds patterns in .git/info/exclude to the excludes list first, and patterns in core.excludesfile are added next.

In last_exclude_matching_from_list(), pattern is searched from the end of the list, and the first matching pattern is used. Therefore the patterns in core.excludesfile are used in precedence to .git/info/exclude.

To meet the precedence described in the document of gitignore, I guess setup_standard_excludes() should be fixed so that patterns in core.excludesfile are added to the list before those in .git/info/ecdlude are added.

Thanks
-- 
  遠藤 陽平 (Yohei Endo)
    yoheie@gmail.com
Next: Junio C Hamano
Message 1 of 4 in “Wrong gitignore precedence?”
  1. Yohei EndoApr 22, 2015
  2. Junio C HamanoApr 22, 2015
  3. Yohei EndoApr 23, 2015
  4. ignore: info/exclude should trump core.excludesfileJunio C Hamano, Apr 22, 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.