Can't launch external merge tool (WinMerge) on Windows
Asked by Joakim Johansson:

I've set the external merge tool to be WinMerge, and I've also tried using the Custom option and pointing it to the exe-file, but I'm having trouble launching either, and I can't find any information on what the custom option needs to work.

When trying to launch external merge tool, a window pops up and disappears really quickly, and no application starts.


Answers:
author: stevestreeting
body: You can only use WinMerge as an external diff tool, not as an external merge tool (that's why it's not in the list of merge tools).

Ironically despite its name, WinMerge is not a proper merge tool, it only does 2-way comparisons rather than the 3-way merge that Git uses.

comments: author: Joakim Johansson
body: Right! Ended up using Beyond Compare. I don't know how I managed to miss the "Merge tool" part and only see the "External diff tool", figures why I couldn't get any merge going. Thanks!


author: Jonathan Demeyer
body: Since 2.16.0 (released 4 days ago), it supports 3-way merges !  


author: Francois du Plessis
body: [@Jonathan Demeyer](/t5/user/viewprofilepage/user-id/902055)do you have a working config example?


author: Jonathan Demeyer
body: [@Francois du Plessis](/t5/user/viewprofilepage/user-id/2023821) I use the "custom" option, give the path to Winmerge and give those arguments :

```
-e -u -dl \"Mine\" -dm \"Merged\" -dr \"Theirs\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"
```


author: Daniel Jonsson
body: [@Jonathan Demeyer](/t5/user/viewprofilepage/user-id/902055)Thank you and God bless


author: Shawn Murphy
body: I guess I need to look into 3-way merge more that Steve Streetling mentions but I have setup WinMerge as an external tool. Here are the settings needed. It sets the display so your local file is on the right site.

The setting location: Tools-\>Options-\>Diff  
External Diff Tool: Custom   
Diff Command: C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe  
Arguments: $LOCAL $REMOTE  
External Merge Tool: Custom   
Merge Command: C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe  
Arguments: /w1 $LOCAL $REMOTE $MERGED

comments: author: Shawn Murphy
body: Update: WinMerge can now do 3 files. So now you can include the base file.

External Diff Tool: WinMerge  
Diff Command: C:\\Program Files\\WinMerge\\WinMergeU.exe  
Arguments:

```
-wl -dl Remote -dr Local \"$REMOTE\" \"$LOCAL\"
```

<br />

External Merge Tool: WinMerge  
Merge Command: C:\\Program Files\\WinMerge\\WinMergeU.exe  
Arguments:

```
-wl -wr -dl Remote -dm Base -dr Local \"$REMOTE\" \"$BASE\" \"$LOCAL\" -o \"$MERGED\"
```

To explain the arguments:

"-wl" makes left file ($Remote) read only so you don't accidentally start editing the wrong file.

"-wr" read only for the right ($Local) file

"-dl Remote" Naming the $Remote file "Remote"

"-dm Base" Naming the $Base file "Base"

"-dr Local" Naming the $Local file "Local"

"-o" sets up $Merged as the output file as your result of the merge.

source: <http://manual.winmerge.org/Command_line.html>

EDIT:20211028 Fix arguments to maintain conventional naming and make the middle file the merge file for a 3 way merge.


author: Guillaume Tong
body: [@Shawn Murphy](/t5/user/viewprofilepage/user-id/629794) Thank you very much for sharing these settings, but I found that there were some parts of your merge arguments that could be improved upon:

1. "-wm" makes the middle file read only, but the middle file is the one we actually want to edit, and this flag therefore disables the very useful auto-merge feature from WinMerge. I replace that with "-wr" to make the right ($Local) file protected instead
2. $LOCAL $BASE $REMOTE $MERGED : These all lack surrounding quotes which are there in other versions of the arguments posed here. I assume these serve to ensure the file names can still work even if they contain spaces and special characters, so I am putting them in.
3. This one is just down to personal preference, but you are naming the Base file as "Base", and the Local file as "Local"... but the Remote file as "PreviousVersion". I personally prefer to follow the simplest convention and name the Remote file as "Remote". (This one does NOT affect functionality, feel free not to include this one)

Please correct me if I am wrong.

This results in the following arguments for merge:

```
-wl -wr -dl Remote -dm Base -dr Local \"$LOCAL\" \"$BASE\" \"$REMOTE\" -o \"$MERGED\"
```


author: Shawn Murphy
body: Thanks [@Guillaume Tong](/t5/user/viewprofilepage/user-id/4193095) . I missed the quotes. Good catch. I'll have to look more into the auto-merge function of WinMerge. I did not know about it.


author: s_kniebuehler
body: Hi,

I think the Remote and the Local must be switch otherwise it will be show not correct in the header names as the opened file.

I think it must be change to this:
>
> ```
> -wl -wr -dl Remote -dm Base -dr Local \"$REMOTE\" \"$BASE\" \"$LOCAL\" -o \"$MERGED\"
> ```


author: Couru D_avance
body: [@s_kniebuehler](/t5/user/viewprofilepage/user-id/3178295) No i don't think so. For me the right anwser is the one [@Guillaume Tong](/t5/user/viewprofilepage/user-id/4193095)

Even though that should be the right behavior, it isn't. It appears that winmerge reverses the order of the files in the application panels. Below my command line

```
-e -u -x -wr -wl -dl \"Local - \"$MERGED\"\" -dm Base -dr \"Remote - \"$LOCAL\"\" \"$REMOTE\" \"$BASE\" \"$LOCAL\" -o \"$MERGED\"
```


author: s_kniebuehler
body: [@Couru D_avance](/t5/user/viewprofilepage/user-id/4355765) I have done a test with winmerge 2.16.6.0 where I have written three files: remote.txt, base.txt and local.txt. I have written in the files the name of the file.  
Then you can easy see what is happen.  

Question to your command line:  
Why do you add $MERGED to the title of the left side? This side is read only.


author: s_kniebuehler
body: see:

[\[SRCTREEWIN-13514\] Adding WinMerge to merge tool selection - Create and track feature requests for Atlassian products.](https://jira.atlassian.com/browse/SRCTREEWIN-13514)


author: Shawn Murphy
body: Thanks [@s_kniebuehler](/t5/user/viewprofilepage/user-id/3178295) . Just did your test with the command line arguments and merging 3 files with their name in each file. The arguments in the Suggestion above were right on.

```
-wl -wr -dl Remote -dm Base -dr Local \"$REMOTE\" \"$BASE\" \"$LOCAL\" -o \"$MERGED\"
```

As for the $Merged on the left, that is requesting WinMerge to pass this file (the final result in the middle pane) back to SourceTree as the result of the merge process. SourceTree then stages that file for commit.


Tags: windows