Discard changes can be very slow
Describe the bug Discarding a bunch of files can take a long time and the UI is frozen during the operation.
To Reproduce Steps to reproduce the behavior:
- Select a decent amount of files (for example a package in node_modules that you don't need anymore)
- Press d to discard
Expected behavior The UI should not lock up. Ideally this operation should be quick but if this is a limitation of git then I would like the operation to happen in the background or at least get some indication telling me that something is happening.
Version info:
Run lazygit --version and paste the result here
commit=6705428a8df4ef3480e8d03a2f5efc87129f0c42, build date=2025-05-22T12:59:02Z, build source=binaryRelease, version=0.51.0, os=linux, arch=amd64, git version=2.48.1
Run git --version and paste the result here
git version 2.48.1
Additional context I'm on Ubuntu 25.04
Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.
Hey thanks for this report!
Some prior art on this (although not duplicates because none of them are primarily centered around performance).
https://github.com/jesseduffield/lazygit/issues/2181 https://github.com/jesseduffield/lazygit/issues/1964
I see discussion on both of these about how we currently loop through each file individually and do a
git checkout -- path/to/file.ext
git checkout -- path/to/file2.ext
git checkout -- path/to/file3.ext
instead of a
git checkout -- path/to
(assuming you are selecting path/to with your cursor)
Not sure why switching to the latter was never implemented.... Looking into it! But it might turn out trickier than I hope
I have done some history diving and I think is where the change to looping through files was introduced: https://github.com/jesseduffield/lazygit/pull/1197
And I believe here are the edge cases being discussed: https://github.com/jesseduffield/lazygit/blob/6705428a8df4ef3480e8d03a2f5efc87129f0c42/pkg/commands/git_commands/working_tree.go#L136-L174
Same issue here. Discarding changes of 100 files lets you think that Lazygit crashed.
Some ideas to improve this: Show a spinner, or a progress bar showing 1 of 100 and counting up. At least then you know it's working.
Same here. Discarding files in Lazygit is orders of magnitude slower than in command line.