Git – Msys Git Merge Tool Command Options Issue

batch-filegitmergeversion control

I'm using msys Git for source control on a Windows machine and I'm trying to figure out how to get my merge tool, WinMerge, to work with Git.

I've followed the instructions on this blog to the best of my ability since it's the closest I've found to what I'm trying to do. Basically what I did was:

Modify my .gitconfig file to include the following:

[merge]
    tool = winmerge

[mergetool "winmerge"]
    cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" "$PWD/$LOCAL" "$PWD/$REMOTE" "$PWD/$MERGED"  
        trustExitCode = false  
    keepBackup = false

This is almost working. When I try to run the merge tool from Git, WinMerge gives me an error saying it can't find the paths of the files, which makes complete sense since the paths it is looking for are:

C:\MY\WORKING\DIRECTORY\-e
C:\MY\WORKING\DIRECTORY\-ub

It looks like Git is passing options into the merge tool instead of the local & remote file names that I would expect to get passed if everything was working correctly.

I've searched online for Git's merge documentation, but I can't seem to find anything related to what I'm trying to do. My guess is that the solution will be one of the following:

  1. Change the $LOCAL & $REMOTE variables to the correct values, assuming $LOCAL & $REMOTE are incorrect.
  2. Write a .bat script to call WinMergeU, and handle the arguments Git sends to the merge tool within the logic of my .bat script.

Best Answer

If you look at the file that is conflicted, you'll notice the standard Theirs >>>>>>> and <<<<<< Mine markers. WinMerge understands these as merge conflicts, so it does not need 'Theirs' and 'Mine' to be specified explicitly; it just needs to be told which file it is that has the conflict markers.

  1. We know the file in the working directory contains the markers.
  2. It makes sense that the file we are merging to will also be this file - we also know that git mergetool makes the $MERGED variable available that names that file.

    [mergetool "winmerge"]
        cmd = 'C:/Program Files/WinMerge/WinMergeU.exe' \"$MERGED\"
    

This is all you need to hook git up with WinMerge for merge/conflict resolution; no scripts or command-line switches needed. Refer to the 3rd command-line form in the docs (linked by the OP, above) and the explanation of conflictfile argument.