Differences between revisions 17 and 18
Revision 17 as of 2015-11-12 02:47:06
Size: 4069
Editor: JohnHein
Comment: Using internal:merge3 can provide more context than internal:merge - so it seems like a better recommendation here.
Revision 18 as of 2017-03-14 01:05:15
Size: 4068
Editor: RyanMcElroy
Comment: Fixed pluralization of 'symlinks' -- in the code the option is just 'symlink'.
Deletions are marked like this. Additions are marked like this.
Line 54: Line 54:
 * symlinks - supports symlinks (False)  * symlink - supports symlinks (False)

Merge Tool Configuration

How to customize which merge tools Mercurial chooses.

1. Introduction

Mercurial delegates most non-trivial file-level merging operations to an external program, called a merge tool. In most installations, Mercurial will automatically search your system for the 'best' available tool, based on a set of known tools in its global configuration.

This tool choice can be extensively customized based on various properties like filename, binary data, running in a GUI, etc.

2. Defining a merge tool

To define a merge tool, add something like the following in .hgrc:

 mymergetool.something = something

which will define mymergetool (the left hand side until the first dot). The option values defines the behaviour of the tool.

For each file changed in both parents Mercurial chooses a merge tool. The merge tool is chosen from the list of file pattern matches in the [merge-patterns] section followed by all tools sorted by decreasing priority order. The list is filtered for whether the executable (defaulting to mymergetool) can be found, whether it supports symlinks or binary files, and whether a GUI is available. To bypass the priority scheme and set the default tool directly, specify the merge tool in [ui] section merge option. For backwards compatibility, the tool hgmerge is implicitly added with lowest priority.

If the chosen merge tool's premerge setting is True then an internal merge is attempted. If the premerge reports no conflicts, then the result will silently be used without running the actual merge tool.

The merge tool is run with an argument list from args with the following variables expanded:

  • $output expands to the existing file which already contains the version from the first parent - and this is also where the result of the merge ends up / must end up

  • $local expands to file.orig which is created as a copy of file in the working directory version - it thus contains the unmerged version from the first parent

  • $base expands to a temporary file which is created with the version from the merge ancestor

  • $other expands to a temporary file which is created with the version from the new second parent revision which the first parent is merged with

Example configuration:

mymergetool.priority = 100
mymergetool.premerge = False
mymergetool.args = $local $other $base -o $output
myimgmerge =

**.jpg = myimgmerge
**.exe = internal:fail

Tool options include:

  • args - the arguments to pass (defaults to $local $base $other)
  • premerge - whether to attempt internal merge first (defaults to True)
  • executable - executable name or path (defaults to <tool>)

  • binary - supports binary files (False)
  • symlink - supports symlinks (False)
  • gui - requires a GUI (False)
  • priority - priority of this tool (0)

3. Internal merge with conflict markers

Mercurial has a selection of "internal" tools for various purposes (see merge-tools for full details). The most interesting of these is internal:merge3, which provides a traditional merge with conflict markers. To set this as your default tool, simply add the following to you config:

merge = internal:merge3

This is not generally recommended as Mercurial gets no direct feedback when merges are successfully completed, and it's not terribly user-friendly compared to modern tools.

(!) When using internal:merge3, you'll want to carefully read the help for the resolve command to avoid losing your merge work.

4. See also


MergeToolConfiguration (last edited 2019-08-07 17:58:24 by GregTatum)