From WSL2 (Ubuntu) how could one use Meld installed natively on Windows as the git merge and diff tool?
So that commands like git mergetool
& git difftool
from WSL open Meld on Windows.
You may edit your git config file by issuing git config --global -e command. Before making any changes remember to create a backup. Above configuration should work on any Linux, for Windows you must replace meld command by absolute path to Meld: \"C:/Program Files (x86)/Meld/Meld.exe\" ( \" are part of the path).
Use the merge resolution program specified by <tool>. Valid values include emerge, gvimdiff, kdiff3, meld, vimdiff, and tortoisemerge. Run git mergetool --tool-help for the list of valid <tool> settings. If a merge resolution program is not specified, git mergetool will use the configuration variable merge.
The only change you have to make is to change the path of the Meld installed file for Mac or Linux. After setting up defaults, you can type `git difftool` within the Git local directory to launch the Windows version of Meld, or you can `git mergetool` to resolve merge conflicts as shown below.
Make meld
easily accessible in WSL by linking it:
sudo ln -s /mnt/c/Program\ Files\ \(x86\)/Meld/Meld.exe /usr/local/bin/meld
In WSL edit ~/.gitconfig
and add:
[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)\"
To make git difftool --dir-diff
work you need to use it with --no-symlinks
(the symbolic links in \\wsl$\
don't seem to currently work when opening from Windows apps). Changes will still be copied back to the source files once Meld is closed. Since I use git dir diff tool a lot I've added these aliases in the above file:
[alias]
dt = !git difftool --dir-diff --no-symlinks -t meld
mt = !git mergetool -t meld
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With