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

后端 未结 26 1918
清酒与你
清酒与你 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 03:56

    Building on VonC's answer to deal with file removals and additions, use the following commands and scripts:

    > git config --global diff.tool winmerge
    > git config --global difftool.winmerge.cmd "winmerge.sh \"$LOCAL\" \"$REMOTE\" \"$BASE\""
    > git config --global difftool.prompt false
    

    Which is the same as putting this in your global .gitconfig:

    [diff]
        tool = winmerge
    [difftool "winmerge"]
        cmd = winmerge.bat "$LOCAL" "$REMOTE" "$BASE"
    [difftool]
        prompt = false
    

    Then put the following in winmerge.shwhich must be on your path:

    #!/bin/sh
    NULL="/dev/null"
    if [ "$2" = "$NULL" ] ; then
        echo "removed: $3"
    elif [ "$1" = "$NULL" ] ; then
        echo "added: $3"
    else
        echo "changed: $3"
        "C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -ub -dl "Base" -dr "Mine" "$1" "$2"
    fi
    

提交回复
热议问题