Force git show to show diff using vimdiff

南笙酒味 提交于 2019-12-23 19:15:19

问题


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?


回答1:


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.




回答2:


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)



回答3:


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.




回答4:


Following works for me:

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


来源:https://stackoverflow.com/questions/37407682/force-git-show-to-show-diff-using-vimdiff

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!