Given a patch (without having both files, e.g.) git show -c > some_patch.c
, is it possible to view this patch in vimdiff with a side-by-side view?
Or does this require having both source and destination files?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityDo you have the original file and the patch file? If yes, you can open the original file in Vim and run
:diffpatch patch-file
If you only have the patch file you can try this command for a start:
:g/^--- .*\n+++ .*/+2;/\(\n--- \|\%$\)/y | tab new | put | %s/^\([- ]\|+.*\n\)// | set nomodified | diffthis | vert new | put | %s/^\([+ ]\|-.*\n\)// | set nomodified | diffthis | tabrewind
This yanks all lines between the start of a diff block and the start of the next diff block or the end of file into the default registers. Then it creates a new tab where the old and the new state will be shown in diff mode in two windows. In both windows the complete patch is inserted. Then in the first window the markers for unchanged and deleted lines (leading spaces and minuses) are removed and all lines added by the patch are completely removed. In the second window the markers for unchanged and added lines (leading spaces and pluses) are removed, as are the complete lines deleted by the patch.
Both windows are put into diff mode and marked as unmodified (just to make it easier to close the windows).
This command assumes that you start it from the first tab. Otherwise it will only create a tab for the first file in a patch, probably because the :g
command is aborted by changing to another buffer and the :tabrewind
at the end will not go back to the correct tab.
delta
for example: github.com/dandavison/delta can show diff's without having the original files.
Jan 20, 2022 at 22:31