vim 2023-02-08

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?

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

and <leader>hp to get a preview

or post-view I guess šŸ™‚

hs stages

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.

šŸ™Œ 1

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

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

Gdiffsplit then dp or dg?

Party time!

looks like there is the dd shortcut for that as well

(I did this 5m ago!)

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.

Ta šŸ™‚

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

X on a file discards changes to the whole file