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

git rm VERY slow for directories with many files.

From
CJChristopher Jefferson <caj21@st-andrews.ac.uk>
Date
Oct 28, 2017, 17:02 UTC
Message-ID
<BEEA4A16-5433-4E6C-A7D7-956C85F27DF3@st-andrews.ac.uk>
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?
Is there any way I can speed up removing this directory?
Chris
Next: brian m. carlson
Message 1 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.