Fork me on GitHub
#vim
<
2023-02-08
>
dharrigan14:02:58

Users of vim-fugitive...say I want to revert a particular diff hunk to the checked out version, I know that I can do Git diff % to show the diffs in the file. Any magic incantation to go to a particular diff hunk and say "ignore all that, give me what it was originally" and thus revert that particular bit of the file?

sheluchin19:02:16

If I understand correctly, you can open the status window with :Git, expand the file of interest with =, navigate to your hunk, do a visual line selection, and then use X to revert it.

🙌 2
daniel.flexiana20:02:19

Nice! I wasn't aware you can do a visual select. I usually just type X and the hunk gets reverted. Also you can type I and then split the hunk in case you want

emilaasa03:02:21

I use https://github.com/airblade/vim-gitgutter#getting-started for what I think you are describing - <leader>hu

dharrigan08:02:57

Oh, I do use that and I did forget about that!

emilaasa14:02:18

and <leader>hp to get a preview

emilaasa14:02:27

or post-view I guess 🙂

dominicm14:02:12

Gdiffsplit then dp or dg?

Proctor18:02:43

looks like there is the dd shortcut for that as well

dominicm14:02:31

(I did this 5m ago!)

dave15:02:46

I don't use vim-fugitive, but just to offer an alternative: • Use git add --patch (or if fugitive lets you do something similar, you can use that) to stage all the parts that you do want to keep. • Make a commit to ensure you don't lose that part. • Use git checkout path/to/the-file-in-question to revert to the checked-out version of that file.

Amit Gold09:02:20

I’m late to the party, but X on a hunk in fugitive discards that hunk.

Amit Gold09:02:32

X on a file discards changes to the whole file