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

Re: git rm VERY slow for directories with many files.

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 28, 2017, 22:31 UTC
Message-ID
<20171028223103.wevq5zf4rjl7ietd@genre.crustytoothpaste.net>
In-Reply-To
<BEEA4A16-5433-4E6C-A7D7-956C85F27DF3@st-andrews.ac.uk>
On Sat, Oct 28, 2017 at 05:02:02PM +0000, Christopher Jefferson wrote:
Show 15 quoted lines
> I stupidly added a directory with many files ( ~450,000 ) to git, and want to delete them — later I plan to rebase/squash various commits to remove the files from the history altogether.
> 
> However, ‘git rm’ is VERY slow. For example, in a directory with 10,000 files (on a Mac), git v2.14.2
> 
> Git add . : 5.95 secs
> Git commit : 1.29 secs
> Git rm -r : 22 secs
> 
> 50,000 files
> 
> Git add . : 25 secs
> Git commit : 11 secs
> Git rm : After 20 minutes, I killed it.
> 
> Looking at an optimized profile, all the time seems to be spent in “get_tree_entry” — I assume there is some huge object representing the directory which is being re-expanded for each file?
Yes, there's a tree object that represents each directory.
> Is there any way I can speed up removing this directory?

First, make sure your working directory is clean with no changes. Then, remove the directory (by hand) or move it somewhere else. Then, run "git add -u".

That should allow you to commit the removal of those files quickly.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
Previous: Christopher JeffersonNext: Junio C Hamano
Message 2 of 6 in “git rm VERY slow for directories with many files.”
  1. Christopher JeffersonOct 28, 2017
  2. brian m. carlsonOct 28, 2017
  3. Junio C HamanoOct 29, 2017
  4. Junio C HamanoOct 29, 2017
  5. brian m. carlsonOct 29, 2017
  6. Junio C HamanoOct 30, 2017

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.