Git: How configure KDiff3 as merge tool and diff tool

前端 未结 7 1062
长情又很酷
长情又很酷 2020-11-28 17:25

Recently I was using GitExtension 2.46, but the Git version that has the same is 1.9.4.msysgit.2. Willing to use only Git commands, I uninstalled GitExtension and install th

7条回答
  •  北海茫月
    2020-11-28 18:00

    (When trying to find out how to use kdiff3 from WSL git I ended up here and got the final pieces, so I'll post my solution for anyone else also stumbling in here while trying to find that answer)

    How to use kdiff3 as diff/merge tool for WSL git

    With Windows update 1903 it is a lot easier; just use wslpath and there is no need to share TMP from Windows to WSL since the Windows side now has access to the WSL filesystem via \wsl$:

    [merge]
        renormalize = true
        guitool = kdiff3
    [diff]
        tool = kdiff3
    [difftool]
        prompt = false
    [difftool "kdiff3"]
        # Unix style paths must be converted to windows path style
        cmd = kdiff3.exe \"`wslpath -w $LOCAL`\" \"`wslpath -w $REMOTE`\"
        trustExitCode = false
    [mergetool]
        keepBackup = false
        prompt = false
    [mergetool "kdiff3"]
        path = kdiff3.exe
        trustExitCode = false
    

    Before Windows update 1903

    Steps for using kdiff3 installed on Windows 10 as diff/merge tool for git in WSL:

    1. Add the kdiff3 installation directory to the Windows Path.
    2. Add TMP to the WSLENV Windows environment variable (WSLENV=TMP/up). The TMP dir will be used by git for temporary files, like previous revisions of files, so the path must be on the windows filesystem for this to work.
    3. Set TMPDIR to TMP in .bashrc:
    # If TMP is passed via WSLENV then use it as TMPDIR
    [[ ! -z "$WSLENV" && ! -z "$TMP" ]] && export TMPDIR=$TMP
    
    1. Convert unix-path to windows-path when calling kdiff3. Sample of my .gitconfig:
    [merge]
        renormalize = true
        guitool = kdiff3
    [diff]
        tool = kdiff3
    [difftool]
        prompt = false
    [difftool "kdiff3"]
        #path = kdiff3.exe
        # Unix style paths must be converted to windows path style by changing '/mnt/c/' or '/c/' to 'c:/'
        cmd = kdiff3.exe \"`echo $LOCAL | sed 's_^\\(/mnt\\)\\?/\\([a-z]\\)/_\\2:/_'`\" \"`echo $REMOTE | sed 's_^\\(/mnt\\)\\?/\\([a-z]\\)/_\\2:/_'`\"
        trustExitCode = false
    [mergetool]
        keepBackup = false
        prompt = false
    [mergetool "kdiff3"]
        path = kdiff3.exe
        trustExitCode = false
    

提交回复
热议问题