I have a diff file generated by
git diff HEAD~2 > alldiff.
Is it possible to view the diff for any one file using
somecmd alldiff file1withchanges will use
alldiff to show changes in
:help diffpatch is your answer.
You just need to say
Other answer before I knew that^
I'm not normally one to recommend plugins, but I recommend using vim-fugitive. There is a command,
:GDiffsplit, that does exactly what you want.
In the buffer you're interested in, simply say
:GDiffsplit HEAD~2 and fugitive will do the rest:
- Get git to create the diff
- open a temp buffer with a copy of the file
- Apply the diff
:diffthison the two buffers
Here is me trying to write that as a vimscript function
function! do_the_fugitive_thing(revision) " Get git to create the diff let my_file = expand("%") let my_patch = "/tmp/ari.patch" system("git diff ".a:revision." -- ".my_file." > ") " open a temp buffer with a copy of the file vsp temp_buffer set filetype=nofile execute "read ".my_file " Apply the diff system("patch < ".my_patch) edit! % " reload buffer after patch application " run `:diffthis` on the two buffers bufdo diffthis endfunction
Let me know if this works! Or if you don't know vimscript enough then don't worry about it and just use the plugin...