Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Msys Git Merge Tool Command Options Issue

Tags:

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.
like image 742
Dan Herbert Avatar asked Mar 11 '09 20:03

Dan Herbert


People also ask

How do I resolve merge conflicts in Mergetool git?

We can manually resolve the merge conflict by editing the content in the bottom pane, and then saving the file using :wqa (Write and Quit all files). Once the conflict resolution is successful, the merged file will be staged for commit. git commit -m 'Merged from multiple branches' .

How do I merge tools in git?

Use git mergetool to run one of several merge utilities to resolve merge conflicts. It is typically run after git merge. If one or more <file> parameters are given, the merge tool program will be run to resolve differences on each file (skipping those without conflicts).

How does git decide to merge?

Instead, Git uses an algorithm to determine what bits of a file have changed and if any of those bits could represent a conflict. For simple text files, Git uses an approach known as the longest common subsequence algorithm to perform merges and to detect merge conflicts.

What are merge tools?

What Is the Merge Tool? The Merge Tool combines data from multiple sources, then adds them into a new data set. It's not only geometry, but it also merges attributes with the option to match fields from input datasets. When you use the Merge Tool, features have to be the same geometry type (points, lines, or polygons).


1 Answers

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.

like image 120
Darren Bishop Avatar answered Oct 23 '22 07:10

Darren Bishop