lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Discard changes can be very slow

Open Dagur opened this issue 7 months ago • 5 comments

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:

  1. Select a decent amount of files (for example a package in node_modules that you don't need anymore)
  2. 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.

Dagur avatar May 22 '25 14:05 Dagur

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

ChrisMcD1 avatar May 23 '25 01:05 ChrisMcD1

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

ChrisMcD1 avatar May 23 '25 01:05 ChrisMcD1

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.

ruudk avatar Aug 29 '25 06:08 ruudk

Same here. Discarding files in Lazygit is orders of magnitude slower than in command line.

samaursa avatar Sep 22 '25 17:09 samaursa