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

Re: top-level gitignore considered harmful

From
TCTomas Carnecky <tomas.carnecky@gmail.com>
Date
Mar 30, 2012, 09:30 UTC
Message-ID
<1333099827-ner-1054@calvin>
In-Reply-To
<20120329211136.GA1112@sigill.intra.peff.net>
On Thu, 29 Mar 2012 17:11:36 -0400, Jeff King <peff@peff.net> wrote:
Show 14 quoted lines
> So we were sitting around chatting today about how slow "git status" is
> in the gigantic WebKit repository (because really, what else would one
> chat about?). Carlos noticed that git spends a lot of time in the
> gitignore code path.  It turns out that the WebKit repository has a
> couple hundred excludes in the top-level .gitignore, many of which are
> for specific files deep in the repository.
> 
> Since these patterns are compared via fnmatch(), we have to process them
> linearly for each entry[1]. And since the patterns are at the top level,
> we check them for each of the ~180,000 files in the repository. So "git
> status" will do O(m*n) work, where "m" is the number of patterns and "n"
> is the number of files in the repository. And as a project grows over
> time, one might expect "m" to be some constant factor of "n". So this is
> really O(n^2) (albeit with some mitigating constant at the front).

Many months ago I noticed that as well, when somebody came to #git and complained that git status is slow (it toook *many* seconds for him). We tracked that down to the fact that his .gitignore contained hundreds of entries. He basically did `git ls-files --other >> .gitignore`, so his .gitignore included every single object file and all other build artefacts. I told him to use wildcards and `git status` became usable again.

tom
Previous: Junio C Hamano
Message 3 of 3 in “top-level gitignore considered harmful”
  1. Jeff KingMar 29, 2012
  2. Junio C HamanoMar 29, 2012
  3. Tomas CarneckyMar 30, 2012

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.