Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Meld as git mergetool & difftool on WSL2?

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.

like image 887
Qtax Avatar asked Sep 09 '20 11:09

Qtax


People also ask

How do I use the meld merge tool in git?

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).

How do I set up Mergetool?

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.

How do you resolve conflict with meld?

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.


1 Answers

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
like image 135
Qtax Avatar answered Oct 07 '22 07:10

Qtax