sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.74k stars 105 forks source link

[Question] Restore specific hunk instead of whole file #368

Closed rodhash closed 1 year ago

rodhash commented 1 year ago

Reading documentation I found option to restore whole file with restore_entry action, by chance can we restore only a hunk?

ie:

I'm reading the DiffviewFileHistory for a given file and found a hunk to be restored, so far I was able to restore whole file not a specific hunk.

Thanks

sindrets commented 1 year ago

Sure. One simple way to do this is to run :DiffviewFileHistory --base=LOCAL. This way the right side of the diff will always be the local version of the file. You can then use all the standard :h copy-diffs mappings for applying any hunks you want.

rodhash commented 1 year ago

Awesome now I'm able to restore hunks.. the commits history navigation seems a bit weird or different now

I don't fully understand why but the left pane now updates in a different way.. but it's fine I guess.. as I move through the commits history I'm able to see the code updating on the right side and I'm able to restore hunks which is the main goal here

sindrets commented 1 year ago

I don't fully understand why but the left pane now updates in a different way

Could you please elaborate?

rodhash commented 1 year ago

Oh sure, let me show you .. It seems I'm not able to attach the video as it exceeds 10MB .. saving it to YT

https://www.youtube.com/watch?v=Kr4hbzH4JKU

1st I'm using just the normal File Hist and the left side updates as I move through the commits.. working as expected here.

Then I use the LOCAL base and we can see that the left side doesn't change/refresh as I move through the different commits.. so it is not behaving the same.

Not sure if this is an issue or not..

That was a personal repo .. I also tried other repos and noticed that sometimes it updates properly

sindrets commented 1 year ago

When --base=LOCAL the right side of the diff will be the local version of the file. It then follows that the diff will reflect all the differences between any given commit and the current state of the file. From what I could tell in the video, you just didn't scroll the diff. All the changes should be there.

rodhash commented 1 year ago

Yeah I just noticed that the left side wasn't updating as used to be but all the changes were there in the right side.. I'd say all good here

Thank you for the help

sindrets commented 1 year ago

The diff is updating correctly. I don't know how else to rephrase this. The diff is a comparison between an old state and the current state of the file. Naturally the diff is going to reflect all the changes made to the file after the old state. The diff hunks will functionally accumulate as you scroll further back in history.