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

后端 未结 26 2228
清酒与你
清酒与你 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条回答
  •  谎友^
    谎友^ (楼主)
    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.

提交回复
热议问题