Re:Guitar – Git GUI Client
by richardwhiuk on Wednesday April 22, 2020 @06:05AM
(#22943977)
`git add -p` is pretty fast for staging parts of files
[ Parent
| on HN ]
Unless I'm missing something - it only shows you a hunk, without much (or any) context. It's relatively fast to stage hunk like this, but you are doing it like blindly.
I use git add -p almost exclusively & I'm a big fan, to me the limitation is when the part I want to stage and the part I don't are so close together that they get presented to me as a single atomic chunk to add/not add.
Do you ever hit 'e' to edit? You can alter the patch manually in Vim/$EDITOR – this is what I do when I hit those edge cases.
Re:Guitar – Git GUI Client
by richardwhiuk on Sunday May 03, 2020 @04:17PM
(#23061542)
You can also press 's' to split in some cases.
Ah no - but I will now!
Still, usually what I need there is the ability to leave a line or two there but don't stage it.
An alternative is using TUI application like vim in conjunction with tools like recountdiff and git apply to handle staging and unstaging parts of files.
You get more context because you can see other parts of the diff in the editor, unlike when using the -p switch with the git add or reset commands.
I'm actually using NeoVIM + fugitive and git-gutter.
GitGutter make working with hunks easy
Looking at the README of vim-gitgutter[1] (assuming that's the plugin you're referring to), it says the following:
>> You cannot unstage a staged hunk.
I'm not sure if that's a feature they plan to support, but something like this could easily be done by highlighting the hunk displayed when running git diff --cached in vim's linewise visual mode and filtering it through git apply -R --cached -.