How to configure my mergetool to not show conflict markers?

1k views Asked by At

I configured git to use SmartSynchronize as the merge tool but when I run git mergetool I still see the conflict markers, like this:

enter image description here (bigger version)

I was using P4Merge and saw that it handles these conflict markers, but I really like viewing the merged file in the middle of the screen like in SmartSynchronize; so am I doing something wrong or is this tool just unable to handle conflict markers?

My .gitconfig:

[mergetool "smartsynchronize"]
cmd = '/C/Program Files (x86)/SmartSynchronize 3.3/bin/smartsynchronize.exe' "$LOCAL" "$REMOTE" "$MERGED"   

(also, if you know a way to make P4Merge show the merged file in the middle like that, I'd love to know)

3

There are 3 answers

0
Edward Thomson On BEST ANSWER

git-mergetool invokes a three-way merge tool - that is, a tool that produces a merge result from two branches and the common ancestor. There are four files in all - three input files and an output file.

However, you are invoking the mergetool with only three inputs: the two branches and the merge result. Thus, it is using the merge result as the common ancestor - the file that git-merge has written the merge file (with conflict markers). Instead, you need to invoke your merge tool with the two sides ($LOCAL, $REMOTE) and the common ancestor $BASE, telling it to place the merge result into $MERGED.

Your 3-way merge tool should be capable of actually distinguishing between the common ancestor and the output file. You should talk to your tool's author to determine if this is true and suggest to them that their tool is deficient if they cannot.

If you really love your deficient merge tool, however, you can create a script that:

  • Copies $BASE to a temporary file
  • Invokes the three-way merge tool using the $LOCAL, $REMOTE and the temporary file
  • Checks the exit code for success and on a successful merge, copies the temporary file to $MERGED
  • Returns the exit code from the merge tool
1
Lazy Badger On

If you see conflict markers on calling visual merge, it means only one:

You have not configured mergetools and internal merge was used silently

The right way of using SmartSynchronize as mergetool in Git is this (type of) snippet in ~/.gitconfig or .git/config (according to post in Syntevo blog)

[merge]
        tool = smartsynchronize
[mergetool "smartsynchronize"]
        cmd = '/C/PATH TO/smartsynchronize.exe' "$LOCAL" "$REMOTE" "$MERGED"
        trustExitCode = false
0
Johann On

The answer at the moment appears to be that it is not possible. I investigated why this does not happen with my meld tool, and in fact, it used to. My version of git (1.8.5.3 on OS X) came with a custom script to launch meld with a fourth parameter --output that allows git to set the target file. When meld is invoked without that fourth parameter, it too shows conflict markers in the output.

p4merge also supports 4 parameters for the 3-way merge.

I believe the makers of SmartSynchronize will have to change it to support both the $BASE argument, for resolving conflicts, and the $MERGED argument for output.