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

Re: speed of git reset -- file

From
Jeff King <peff@peff.net>
Date
May 31, 2011, 21:26 UTC
Message-ID
<20110531212639.GA13234@sigill.intra.peff.net>
In-Reply-To
<20110531190015.GA12113@gnu.kitenet.net>
On Tue, May 31, 2011 at 03:00:15PM -0400, Joey Hess wrote:
Show 5 quoted lines
> I'd expect that resetting a single file would need to update the index,
> reading some objects from .git to do it.
> 
> But according to strace, it also stats every file in the working tree.
> I have lots of files, and so that is very slow. Is it really necessary?

Conceptually, no, I don't think so. But remember that your "file" is not really a file at all, but a pathspec that may match many entries. Also, we try not to overwrite things that would not be changed. So that complicates it a little bit.

You can see the implementation in builtin/reset.c:read_from_tree. We actually diff the tree (e.g., HEAD) against the index, and update only the differences. Unfortunately this seems to trash the index (see the comment there), and we end up having to refresh it. I'm not sure how avoidable that trashing is. I think we're getting deep into how unpack_trees works, and it handles a lot more cases than just "unpack a few entries". So I don't know how easy it would be to separate this relatively simple case from more complex ones.

-Peff
Previous: Joey HessNext: Junio C Hamano
Message 2 of 17 in “speed of git reset -- file”
  1. Joey HessMay 31, 2011
  2. Jeff KingMay 31, 2011
  3. Junio C HamanoMay 31, 2011
  4. Jeff KingMay 31, 2011
  5. Matthieu MoyMay 31, 2011
  6. Nguyen Thai Ngoc DuyJun 1, 2011
  7. Junio C HamanoMay 31, 2011
  8. Jeff KingJun 1, 2011
  9. Joey HessJun 1, 2011
  10. Jeff KingJun 1, 2011
  11. Joey HessJun 1, 2011
  12. Jeff KingJun 1, 2011
  13. Joey HessJun 1, 2011
  14. Jeff KingJun 2, 2011
  15. Joey HessJun 2, 2011
  16. Joey HessJun 2, 2011
  17. Junio C HamanoJun 1, 2011

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.