Fork me on GitHub

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?


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

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 for what I think you are describing - <leader>hu


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


and <leader>hp to get a preview


or post-view I guess 🙂


Gdiffsplit then dp or dg?


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.

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