2 minutes

Geschreven door: joost

Mercurial and Merging with IntelliJ

Read how to configure the visual merge tool from intellij as the default merge tool for Mercurial.

  • tooling

If you work on projects with a team like we do, you probably have encountered a merge-conflict or two in your time… And most likely the default merge tool which Mercurial has picked isn’t really helping you.

Before Us Media moved from Subversion to Mercurial I always used the merge-tool of IntelliJ to fix SVN conflicts. So being used to this tool, I wanted to configure it as the default merging tool for Mercurial conflicts.

Configuring the tool

Luckily most of the configuring is cleary explained on the mercurial-wiki. Most of my troubles were trying to find out in which order merge was expecting it’s parameters. But after some fiddling (and yes, googling) success!

Simply add this goody goodness in your .hgrc:

idea =
idea.gui = True
idea.args = merge $local $base $other $output
idea.priority = 1000
idea.executable = /<PATH-TO-IDEA>/bin/

And don’t forget to set the new merge tool as your default:

merge = idea

And you’re ready to go. Since I’m too lazy to explain each line, I’m just going to point you to the appropriate wiki-page for more info.

IDE Version

That being said, this setup didn’t work for me initially, but after some more research I found out this was because the merge tool was expecting only 3 parameters (instead of 4). Luckily the guys at Jetbrains have fixed it by now, just be sure you are using IntelliJ 12 or newer.

Other merge tools

Of course if you rather want to use a different merge tool you can use the same configuration steps, but keep in mind that Mercurial already ships a good set of default configurations. So be sure to check out if your tool isn’t already listed, and if it is, simply set that tool as your default.

File changes in memory

One extra point to keep in mind, the merge tool changes the file in memory. So when you’re done merging and you click ‘Apply’ you might get a series of popups from IDEA asking you which file changes to keep (simply use the in-memory changes). You can circumvent this by simply hitting CTRL + S in the middle pane before hitting ‘Apply’. This way you force the merge tool to save the file on disk before closing itself.

For more information on configuring the hgrc file you can go the wiki. And if you want more information on the comman line interface of the merge tool simply go here.


contact us for a chat and discuss if we are the right partner for you.