lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Feature request: discard changes from selected files only

Open insane-dreamer opened this issue 1 year ago • 7 comments

It would be nice to be able to discard changes from certain files only (the currently selected file(s) in the Commit panel, which are also displayed in the "Unstaged changes" panel)

when pressing d (discard), there could be an additional option to Discard changes from selected files

insane-dreamer avatar May 31 '24 01:05 insane-dreamer

If I understood you correctly, resetting just the currently selected file in the commits view to HEAD?

mark2185 avatar May 31 '24 01:05 mark2185

Yes, that's correct (one or more files if multiple files are selected)

insane-dreamer avatar May 31 '24 03:05 insane-dreamer

Actually, it turns out that this feature already exists. Select multiple files, press d and then select Discard all changes. I just didn't notice it because the wording sounds like it will discard all staged/unstaged changes, not just from the selected files. So maybe the only requested change would be to change the wording to Discard all changes from selected files (when one or more files are selected).

insane-dreamer avatar Jun 21 '24 16:06 insane-dreamer

We already have a pretty prominent tooltip telling you this, isn't that enough? Of course it's also easy to change the wording of the command like you suggest, I was just wondering.

stefanhaller avatar Jun 21 '24 16:06 stefanhaller

Yeah, the tooltip is probably sufficient -- it does list the affected files. The rewording could be useful, but certainly not essential.

insane-dreamer avatar Jun 21 '24 18:06 insane-dreamer

I just realized that the real issue is probably that we only show the "Discard unstaged changes" item when a file with both unstaged and staged changes is selected; otherwise we only show the "Discard all changes" entry, and in that case it's not clear that "all" is meant in contrast to "unstaged", and not "all files in the working copy". I opened #3683 to improve that, if you want to have a look at that.

stefanhaller avatar Jun 21 '24 19:06 stefanhaller

Just tried lazygit and was also confused by this. I had unstaged changes to a file and and staged new file change which I could not rest/unstage/restore that new file without completely discarding unstaged changes to the same file. Which option in lazygit does git restore --staged <file>?

shishkin avatar Jul 23 '24 17:07 shishkin