[Feature Request] Discard staged only
Is your feature request related to a problem? Please describe.
I am in a situation where I need the staged and keep the unstaged changes unstaged.
We may also need to do this with a single file that is partially staged.
Describe the solution you'd like
- In the reset menu options which opens by pressing D, we should find an option to discard staged changes only.
- It is reasonable also to have this option for the discard changes for one file menu, which opened by pressing d
Describe alternatives you've considered
patch -p1 -R < <(git diff --cached) && git reset
Additional context


@MuhammadSawalhy that code snippet you posted looks a little gnarly. Do you know of any other way to achieve the same result?
Do you know of any other way to achieve the same result?
I searched google for help and got this StackOverflow answer
git stash save --keep-index
git reset --hard
git stash pop
In my case the above solution doesn't work for me, I just copy-pasted it here without trying it. So I think we can go with another trick
git commit -m "temp commit"
git stash
git reset --hard HEAD^
git stash pop
We already have the stash only staged changes provided by #1870 so this could technically be done by:
- stash only staged changes
- drop stash
@jesseduffield I could write it up and open a PR if that sounds like a reasonable approach, what do you think?
Sounds good to me @mark2185
@MuhammadSawalhy could you give latest master a try?
The feature you requested should be there, if that's the case feel free to close the issue :)
With my poor connection, it seems that I am cloning tons of files 😅

Discarding only staged changes is working 🎉, but there is no option to discard only staged changes of a specific file:

You're right, if a file is partially staged we currently offer to discard either everything or just the unstaged changes.
I'll take a look into that and get back to you.
Hi there, can we prioritize this issue? I would like to be able to "Drop Staged changes" only, without having to drop everything that is unstaged for a single file.
Right now I cant "drop a staged hunk/selection"s with a single keypress as well, first those hunks/selections have to be unstaged, then I need to reselect them and can discard. This flow needs to improve significantly.
@izelnakri it's not clear to me how to implement either of those features: if you would like to do some digging and propose a solution using git CLI commands, or find another open source git UI that supports the feature, that will help move this issue along.
Specifically regarding dropping a staged hunk, that sounds especially tricky because the hunk's context often changes upon being unstaged, so if we tried removing the patch in two steps: first unstaging it, then removing it, it may simply not work.
Hi @jesseduffield first of all, thanks alot for this amazing tool! Its been a productivity boost, I don't have to tmux switch panes and run most of my git commands anymore.
Secondly, I've seen a tendency of declaring certain issues as "technically impossible". Maybe thats a coincidence I've seen a similar thing here, and in both cases issues are technically possible: https://github.com/jesseduffield/lazygit/issues/3297#issuecomment-1923372937 this issue is actually ongoing on https://github.com/jesseduffield/lazygit/issues/2117
I know that these issues are technically possible because I've been using these features on Vimagit for the last 6 years: https://github.com/jreybert/vimagit . They have been working really well and helped me achieve certain levels of productivity that now Im at a great extent missing in lazygit.
I'll have a look on how they implement it and describe it here if needed. I don't write in go language usually so I'm not very comfortable with it although understand most/all of it almost. I might also able to take a stab at it, probably in the next couple of months due to my current workload.