username_4567
username_4567

Reputation: 4923

Force git show to show diff using vimdiff

How do I do this? After doing changes via git config I can diff my staged and committed changes with vimdiff but when I do git show I still see the diff in old plain style. How do I make this work for git show as well?

Upvotes: 6

Views: 6528

Answers (4)

Deqing
Deqing

Reputation: 14652

Following works for me:

git difftool SHA^..SHA -- <file>

Upvotes: 4

yozniak
yozniak

Reputation: 695

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 see how it works, get familiar with this page.

Upvotes: 4

diwo
diwo

Reputation: 376

The default git show with no parameter as well as git show <object> display changes to all files within a commit. Since vimdiff can only compare a single file at a time, you cannot use it with these options.

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

git difftool SHA~:SHA -- <file>

If you need more flexibility, you can always use git show to fetch specific versions of a file and pass them into vimdiff via Process Substituion

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

Upvotes: 4

toydarian
toydarian

Reputation: 4584

With git show you can show objects like commits (see the man page for reference). So you don't show a diff of two files, but changes in (maybe multiple) files. So there are not two files, which can be compared. But that is exactly what vimdiff does, it opens two files side-by-side and highlights differences.
When you use git difftool or something like that it will create files for both sides of the diff and use the tool (in your case vimdiff) to compare them. git show does not create those files, so its output can't be shown by vimdiff.

tl;dr: git show is a tool to display git objects, not to create diffs, so its output can't be shown as a diff using vimdiff.

What you might want to do is to use git difftool. It will open gvimdiff for every modified file.
You can use the usual options of git diff to compare different commits.

Upvotes: 2

Related Questions