(当尝试从WSL git中查找如何使用kdiff3时,我在这里结束并获得了最后的文章,因此,我将把我的解决方案发布给在这里寻找答案的其他绊脚石的人)
如何将Kdiff3用作WSL git的差异/合并工具
使用Windows 1903更新,它变得容易得多。只需使用wslpath即可,而无需从Windows与WSL共享TMP,因为Windows端现在可以通过\ wsl $访问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
Windows更新1903年之前
将Windows 10上安装的kdiff3用作WSL中git的差异/合并工具的步骤:
- 将kdiff3安装目录添加到Windows路径。
- 将TMP添加到WSLENV Windows环境变量(WSLENV = TMP / up)。git将TMP目录用于临时文件,例如文件的先前版本,因此该路径必须在Windows文件系统上才能起作用。
- 在.bashrc中将TMPDIR设置为TMP:
# If TMP is passed via WSLENV then use it as TMPDIR
[[ ! -z "$WSLENV" && ! -z "$TMP" ]] && export TMPDIR=$TMP
- 调用kdiff3时,将unix-path转换为Windows-path。我的.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