gitsigns.nvim
gitsigns.nvim copied to clipboard
Unstage hunk
Is your feature request related to a problem? Please describe.
I regularly use git reset --patch
as the inverse of git add --patch
and need to do this manually right now.
Describe the solution you'd like
It would be great if I could map <leader>hu
to an unstage_hunk
function instead of undo_stage_hunk
which is limited to the last hunk that was staged.
Describe alternatives you've considered
- At first I expected that
undo_stage_hunk
to matchgit reset --patch
, but of course this is not the case. - I believe
reset_hunk
is effectively a--hard
git reset, orgit checkout --patch
. -
reset_buffer_index
unstages everything in the buffer which is usually not what I want
So I normally use :!git reset -p %
which is more time consuming.
Additional context
-
It's easy for me to understand the behavior of an
unstage_hunk
function because I frequently usegit reset -p
. However I expect it would be more clear to others if secondary signs as described in https://github.com/lewis6991/gitsigns.nvim/pull/303 and https://github.com/lewis6991/gitsigns.nvim/issues/440. I expect thatunstage_hunk
would effectively operate on hunks indicated by secondary signs. -
Adding an optional
range
argument, similar to the range argument instage_hunk(range)
would also be handy. I've often found it difficult to edit patches withgit reset --patch
, so I'm not sure if this would be tricky to implement in practice.
Without secondary signs, how do you expect this to work exactly? What would the implementation roughly do?
I actually do think you probably want the secondary signs first.
Without it, I imagine I would just put the cursor on a line that I know is part of a staged hunk and <leader>hu
. (Or highlight some lines in visual mode I know probably intersects with a staged hunk and hit <leader>hu
.) That is far from ideal though.
(I usually know what it is because it's usually something like a commented out piece of code or a TODO that I accidentally staged at some point)