在WSL2 Windows 11上使用Beyond Compare(4)打开git仓库版本失败

5

我试图让git和Beyond Compare在WSL上顺利配合。以下是git config --list的输出:

diff.tool=bc3
difftool.prompt=false
difftool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe
merge.tool=bc3
mergetool.prompt=false
mergetool.bc3.trustexitcode=true
mergetool.bc3.path=/mnt/c/Program Files/Beyond Compare 4/BComp.exe

这是我的~/.gitconfig文件:

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    trustExitCode = true
    path = /mnt/c/Program Files/Beyond Compare 4/BComp.exe

我的 git --version 是:

git version 2.25.1

当我尝试运行命令git difftool file_in_git_repo时,Beyond Compare会打开左侧窗口显示当前版本,但右侧窗口没有内容(我已确认文件在git repo中存在)。 .git/config文件中没有任何与diff或merge相关的条目。
如有任何建议,请不吝赐教。
类似于VonC的建议,我在我的.gitconfig文件中添加了以下内容后成功解决问题(免责声明 - 我尚未使用此新方法进行合并工具):
[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe'   \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
[merge]
    tool = bc3
[mergetool]
    prompt = false
[mergetool "bc3"]
    trustExitCode = true
    cmd = '/mnt/c/Program Files/Beyond Compare 4/BComp.exe'   \"$(wslpath -aw $LOCAL)\" \"$(wslpath -aw $REMOTE)\"
2个回答

6

检查一下 这个配置 是否适用于你的情况:

I managed to get it working using the built-in wslpath command which comes with new WSL versions!

My git config on WSL linux side:

difftool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
mergetool.bc3.cmd=BComp.exe "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"

BComp.exe is in my $PATH.
I'm using WSL2 on Windows version 2004 (build 19041), and this works both inside the WSL filesystem and also for the mounted Windows filesystem.

The new wslpath -aw converts the Linux paths like this:

$ wslpath -aw /home/
\\wsl$\Debian\home

And Windows paths like this:

$ wslpath -aw /mnt/c/Users/
C:\Users

This makes them both work perfectly with the Windows version of BC when launched from Linux.


1

VonC的解决方案让我接近成功,但似乎无法与dir-diff一起使用,即git difftool -d。为了使其工作,我需要在WSL2端的.gitconfig中添加以下内容。

[core]
    symlinks = false

另外,您还可以运行 git difftool -d --no-symlinks


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接