gitsigns.nvim icon indicating copy to clipboard operation
gitsigns.nvim copied to clipboard

Unstage hunk

Open rehno-lindeque opened this issue 2 years ago • 3 comments

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 match git reset --patch, but of course this is not the case.
  • I believe reset_hunk is effectively a --hard git reset, or git 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 use git 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 that unstage_hunk would effectively operate on hunks indicated by secondary signs.

  • Adding an optional range argument, similar to the range argument in stage_hunk(range) would also be handy. I've often found it difficult to edit patches with git reset --patch, so I'm not sure if this would be tricky to implement in practice.

rehno-lindeque avatar Apr 04 '22 01:04 rehno-lindeque

Without secondary signs, how do you expect this to work exactly? What would the implementation roughly do?

lewis6991 avatar Apr 12 '22 16:04 lewis6991

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.

rehno-lindeque avatar Apr 12 '22 20:04 rehno-lindeque

(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)

rehno-lindeque avatar Apr 12 '22 20:04 rehno-lindeque