git - 如何在 WSL2 上将 Meld 用作 git mergetool 和 difftool?

标签 git windows-subsystem-for-linux meld wsl-2

在 WSL2 (Ubuntu) 中,如何使用在 Windows 上本地安装的 Meld 作为 git merge 和 diff 工具?
所以像 git mergetool 这样的命令& git difftool从 WSL 在 Windows 上打开 Meld。

最佳答案

制作 meld通过链接可以在 WSL 中轻松访问:

sudo ln -s /mnt/c/Program\ Files\ \(x86\)/Meld/Meld.exe /usr/local/bin/meld
在 WSL 中编辑 ~/.gitconfig并添加:
[diff]
        tool = meld
[difftool "meld"]
        cmd = meld \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
[merge]
        tool = meld
[mergetool "meld"]
        cmd = meld --auto-merge \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $BASE)\" \"$(wslpath -aw $REMOTE)\" --output \"$(wslpath -aw $MERGED)\" --label=Local --label=Base --label=Remote --diff \"$(wslpath -aw $BASE)\" \"$(wslpath -aw $LOCAL)\" --diff \"$(wslpath -aw $BASE)\" \"$(wslpath -aw $REMOTE)\"
制作 git difftool --dir-diff工作,您需要将它与 --no-symlinks 一起使用(从 Windows 应用程序打开时,\\wsl$\ 中的符号链接(symbolic link)目前似乎不起作用)。一旦 Meld 关闭,更改仍将被复制回源文件。因为我经常使用 git dir diff 工具,所以我在上面的文件中添加了这些别名:
[alias]
        dt = !git difftool --dir-diff --no-symlinks -t meld
        mt = !git mergetool -t meld

关于git - 如何在 WSL2 上将 Meld 用作 git mergetool 和 difftool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63810361/

相关文章:

Git "Cannot merge binary files"持续集成构建错误

Github:克隆后如何 fork ?

python - 用于从模板创建新的 GitHub 存储库的 Bash 脚本

linux - 在哪些用例中我需要 WSL

Git 运行 Meld 作为 merge 工具失败 'check_requirements import gi'

git - 将标签作为 Docker 容器内的环境变量进行访问

git - 我应该在哪里上传 github 分支的构建文件?

expo - 无法连接到 TCP 端口 : Connection refused when trying to open Expo app on Android Emulator in WSL2

在 Windows 上使用 Meld 的 Git mergetool

git - 使用 meld 作为 diff 工具时查看 git 过滤器输出