How do I view 'git diff' output with my pr

2018-12-31 06:10发布

When I type git diff, I want to view the output with my visual diff tool of choice (SourceGear "diffmerge" on Windows). How do I configure git to do this?

26条回答
只若初见
2楼-- · 2018-12-31 06:33

If you happen to already have a diff tool associated with filetypes (say, because you installed TortoiseSVN which comes with a diff viewer) you could just pipe the regular git diff output to a "temp" file, then just open that file directly without needing to know anything about the viewer:

git diff > "~/temp.diff" && start "~/temp.diff"

Setting it as a global alias works even better: git what

[alias]
    what = "!f() { git diff > "~/temp.diff" && start "~/temp.diff"; }; f"
查看更多
浮光初槿花落
3楼-- · 2018-12-31 06:35

You may want to try out xd http://github.com/jiqingtang/xd, which is GUI wrapper for GIT/SVN diff. It is NOT a diff tool itself. You run xd when you want to run git diff or svn diff and it will show you a list of files, a preview window and you can launch any diff tool you like, including tkdiff, xxdiff, gvimdiff, emacs(ediff), xemacs(ediff), meld, diffuse, kompare and kdiff3. You can also run any custom tool.

Unfortunately the tool doesn't support Windows.

Disclosure: I am the author of this tool.

查看更多
妖精总统
4楼-- · 2018-12-31 06:36

With new git difftool, its as simple as adding this to your .gitconfig file:

[diff]
    tool = any-name
[difftool "any-name"]
    cmd = "\"C:/path/to/my/ext/diff.exe\" \"$LOCAL\" \"$REMOTE\""

Also check out diffall, a simple script I wrote to extend the annoying (IMO) default diff behaviour of opening each in serial.

查看更多
孤独寂梦人
5楼-- · 2018-12-31 06:37

For a linux version of how to configure a diff tool on git versions prior to 1.6.3 (1.6.3 added difftool to git) this is a great concise tutorial,

in brief:

Step 1: add this to your .gitconfig

[diff]
  external = git_diff_wrapper
[pager]
  diff =

Step 2: create a file named git_diff_wrapper, put it somewhere in your $PATH

#!/bin/sh

vimdiff "$2" "$5"
查看更多
千与千寻千般痛.
6楼-- · 2018-12-31 06:39

On Mac OS X,

git difftool -t diffuse 

does the job for me in the git folder. For installing diffuse, one can use port -

sudo port install diffuse
查看更多
不流泪的眼
7楼-- · 2018-12-31 06:41

I tried the fancy stuff here (with tkdiff) and nothing worked for me. So I wrote the following script, tkgitdiff. It does what I need it to do.

$ cat tkgitdiff
#!/bin/sh

#
# tkdiff for git.
# Gives you the diff between HEAD and the current state of your file.
#

newfile=$1
git diff HEAD -- $newfile > /tmp/patch.dat
cp $newfile /tmp
savedPWD=$PWD
cd /tmp
patch -R $newfile < patch.dat
cd $savedPWD
tkdiff /tmp/$newfile $newfile
查看更多
登录 后发表回答