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

Re: git 2.34.0: Behavior of `**` in gitignore is different from previous versions.

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 21, 2021, 00:46 UTC
Message-ID
<xmqq5ysmnxnx.fsf@gitster.g>
In-Reply-To
<CAPx1GveHusi8n8n03hUwBu6B3=_j0ZY6FWXWKDs8mLGwHEN-Qg@mail.gmail.com>
Chris Torek <chris.torek@gmail.com> writes:
Show 23 quoted lines
> ...  So the standard
> explanation -- at least, the one I use -- is this:
>
>  * Git opens and reads the working tree directory.  For each file
>    or directory that is actually present here, Git checks it
>    against the ignore rules.  Some rules match only directories
>    and others match both directories and files.  Some rules say
>    "do ignore" and some say "do not ignore".
>
>  * The *last* applicable rule wins.
>
>  * If this is a file and the file is ignored, it's ignored.
>    Unless, that is, it's in the index already, because then it's
>    tracked and can't be ignored.
>
>  * If this is a directory and the directory is ignored, it's
>    not even opened and read.  It's not in the index because
>    directories are never in the index (at least nominally).
>    If it is opened and read, the entire set of rules here
>    apply recursively.
>
> This works, but skips over files that are in the index and are in
> a directory that won't be read.  So I add one last rule, which is

All of the above is sensible. If you deal with a path that is in the index upfront, you can simplify the later rules somewhat, I would think. I.e. add a first rule before everything else that says:

 * A file in the index is not ignored.  Everything below is about a
   path not in the index.

Then your third rule can lose "Unless...", and you do not have to add one last rule outside the bulleted list, either.

;-)
Previous: Chris TorekNext: Philip Oakley
Message 11 of 13 in “git 2.34.0: Behavior of `**` in gitignore is different from previous versions.”
  1. Danial AlihosseiniNov 18, 2021
  2. Jeff KingNov 18, 2021
  3. Derrick StoleeNov 18, 2021
  4. Danial AlihosseiniNov 19, 2021
  5. Derrick StoleeNov 19, 2021
  6. Danial AlihosseiniNov 19, 2021
  7. Johannes SixtNov 19, 2021
  8. Derrick StoleeNov 19, 2021
  9. Ævar Arnfjörð BjarmasonNov 19, 2021
  10. Chris TorekNov 20, 2021
  11. Junio C HamanoNov 21, 2021
  12. Philip OakleyNov 23, 2021
  13. Danial AlihosseiniNov 23, 2021

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.