Force git show to show diff using vimdiff

How can I do it? After making the changes through git config I can separate my step-by-step and fixed changes using vimdiff, but when I do git show , I still see diff in the old normal style. How do I make this work for git show ?

+1
git vim vimdiff
source share
3 answers

With git show you can show objects like commits ( see the man page for help ). This way you do not show diff of two files, but change files (possibly several). Thus, there are no two files that can be compared. But this is exactly what vimdiff does, it opens two files side by side and highlights the differences.
When you use git difftool or something like this, it will create files for both sides of the diff and use a tool (in your case vimdiff) to compare them. git show does not create these files, so its output cannot be displayed by vimdiff.

tl; dr: git show is a tool for displaying git objects, not for creating diff, so its output cannot be shown as diff using vimdiff.

What you can do is use git difftool . It will open gvimdiff for each changed file.
You can use the usual git diff options to compare different commits.

+1
source share

The default value of git show without a parameter, as well as git show <object> displays changes to all files in the commit. Since vimdiff can only compare one file at a time, you cannot use it with these parameters.

However, git show <object> -- <file> shows the changes in a single file inside the commit. You can display the changes in vimdiff by running difftool :

 git difftool SHA~:SHA -- <file> 

If you need more flexibility, you can always use git show to extract certain versions of a file and transfer them to vimdiff via Process Substituion

 export FILE=path/to/file; vimdiff <(git show SHA1:$FILE) <(git show SHA2:$FILE) 
+1
source share

Try using git aliases. This is for git show

 git config --global alias.s difftool\ HEAD^\ HEAD 

And this is for git show <revision>

 git config --global alias.s '!f() { rev=${1-HEAD}; git difftool $rev^ $rev; }; f' 

To find out how it works, check out this page .

0
source share

All Articles