[Update: see Merging with Mercurial 1.0 and Meld for more up-to-date info on the experience with Mercurial 1.0, which comes with Ubuntu 8.10.]
When confronted with a merge conflict, Mercurial 0.9.5 (the version that comes with Ubuntu 8.04) uses its hgmerge script to call meld in a way that displays your version of the file on the left, the other version on the right, and hg’s attempt to merge them in the middle, with conflict markers where it was unable to do so.
Here’s meld handling the Merging conflicting changes example from the hg book:
You’re supposed to fix the one in the middle, resolving the conflicts between the ones on either side, and then save the middle one (which will get saved to your working directory, from where you can commit your merge).
The following patch hacks hgmerge to display the base version (the one from which your version and the other version originated) on the left, the other version on the right, and your version in the middle.
--- hgmerge.orig 2008-06-01 13:51:10.000000000 -0700
+++ hgmerge 2008-06-01 14:35:46.000000000 -0700
@@ -158,13 +158,12 @@
if [ -n "$MELD" ]; then
+ cp "$BACKUP" "$LOCAL"
cp "$BACKUP" "$CHGTEST"
# protect our feet - meld allows us to save to the left file
- cp "$BACKUP" "$LOCAL.tmp.$RAND"
- # Meld doesn't have automatic merging, so to reduce intervention
- # use the file with conflicts
+ cp "$BASE" "$LOCAL.tmp.$RAND"
$MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure
# Also it doesn't return good error code
$TEST "$LOCAL" -nt "$CHGTEST" && conflicts_or_success || ask_if_merged
Here again you’re supposed to fix and save the file in the middle, which gets saved to your working directory.
Here’s what the example looks like using the hacked version of hgmerge:
After trying both versions of the script on several test and real merges (a few of which I screwed up), it’s still not clear to me which approach is better (or if there’s something better still). David Baron pointed out in a conversation that it can be useful to see the base version, but it’s also useful to distinguish between your version and the version that ultimately results from the merge (which is presumably why kdiff3, which is shown in the book, displays all four: base, yours, other, and final).
(Note: Devmo’s Mercurial basics says to use Mercurial version 1.0 or later, although I hear that doesn’t even include hgmerge, leaving configuration of a merge tool entirely up to each user, so the question is even more significant there.)