How do I view 'git diff' output with my preferred diff tool/ viewer?

后端 未结 26 1862
清酒与你
清酒与你 2020-11-22 03:20

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条回答
  • 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"
    
    0 讨论(0)
  • 2020-11-22 04:03

    The following can be gleaned from the other answers here, but for me it's difficult, (too much information), so here's the 'just type it in' answer for tkdiff:

    git difftool --tool=tkdiff <path to the file to be diffed>
    

    You can substitute the executable name of your favorite diffing tool for tkdiff. As long as (e.g. tkdiff), (or your favorite diffing tool) is in your PATH, it will be launched.

    0 讨论(0)
  • 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\""
    

    Optionally, also add:

    [difftool]
        prompt = false
    

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

    Global .gitconfig on Windows is in %USERPROFILE%\.gitconfig

    0 讨论(0)
  • 2020-11-22 04:07

    I use kompare on ubuntu:

    sudo apt-get install kompare
    

    To compare two branches:

    git difftool -t kompare <my_branch> master
    
    0 讨论(0)
  • 2020-11-22 04:07

    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.

    0 讨论(0)
  • 2020-11-22 04:08

    I've been using this bit in ~/.gitconfig for a long time:

    [diff]
        external = ~/Dropbox/source/bash/git-meld
    

    With git-meld:

    #!/bin/bash
    if [ "$DISPLAY" = "" ];
    then
        diff $2 $5
    else
        meld $2 $5
    fi
    

    But now I got tired of always using meld in graphical environment, and it's not trivial to invoke the normal diff with this setup, so I switched to this:

    [alias]
        v =  "!sh -c 'if [ $# -eq 0 ] ; then git difftool -y -t meld ; else git difftool -y $@ ; fi' -"
    

    With this setup, things like this work:

    git v
    git v --staged
    git v -t kompare
    git v --staged -t tkdiff
    

    And I still get to keep the good old git diff.

    0 讨论(0)
提交回复
热议问题