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

git stash takes excessively long when many untracked files present

From
Josh Triplett <josh@joshtriplett.org>
Date
Aug 10, 2013, 21:44 UTC
Message-ID
<20130810214453.GA5719@jtriplet-mobl1>
[CCing folks involved in the recent "stash-refuse-to-kill" merge.]

I keep portions of my home directory in git. I tried to "git stash" some local changes, and it ran for several minutes with no progress. ps showed that it was running "git ls-files --killed", which was taking 100% CPU, and occasionally reading the disk very slowly.

strace shows that git ls-files --killed is doing a full recursive enumeration of my entire home directory. That's a Really Bad Idea:

~$ find | wc -l 3248997 ~$ find -type d | wc -l 350680

Not only that, but it also appears to be attempting to stat and open several files in every single directory; for instance:

stat(".ccache/1/3/.git", 0x7fff254bc7a0) = -1 ENOENT (No such file or directory) open(".ccache/1/3/.git/HEAD", O_RDONLY) = -1 ENOENT (No such file or directory) stat(".ccache/1/3/.git", 0x7fff254bc770) = -1 ENOENT (No such file or directory) open(".ccache/1/3/.git/packed-refs", O_RDONLY) = -1 ENOENT (No such file or directory)

(Yes, in that order.)

I see a lot of room for optimization here. Most importantly, git ls-files --killed really doesn't need to look at any directory entry unless something in the index would conflict with it.

- Josh Triplett
Next: Anders Darander
Message 1 of 15 in “git stash takes excessively long when many untracked files present”
  1. Josh TriplettAug 10, 2013
  2. Anders DaranderAug 13, 2013
  3. Junio C HamanoAug 13, 2013
  4. Anders DaranderAug 13, 2013
  5. Junio C HamanoAug 13, 2013
  6. Junio C HamanoAug 13, 2013
  7. Junio C HamanoAug 15, 2013
  8. Josh TriplettAug 15, 2013
  9. Junio C HamanoAug 15, 2013
  10. Junio C HamanoAug 15, 2013
  11. 0/3 Optimizing "ls-files -k"Junio C Hamano, Aug 15, 2013
  12. 1/3 dir.c: use the cache_* macro to access the current indexJunio C Hamano, Aug 15, 2013
  13. 2/3 ls-files -k: a directory only can be killed if the index has a non-directoryJunio C Hamano, Aug 15, 2013
  14. 3/3 t3010: update to demonstrate "ls-files -k" optimization pitfallsJunio C Hamano, Aug 15, 2013
  15. 4/3 git stash: avoid data loss when "git stash save" kills a directoryJunio C Hamano, Aug 15, 2013

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.