I'm trying to do a complicated merge in a complicated hg repository. I'm not happy with the "newest shared ancestor" that Mercurial chooses to use as the "base" to perform the merge.
I'd like to specify a specific commit of my own choice to use as base.
Is this possible, and if so, how?
Mercurial 3.0: You can now select the ancestor to use as a merge base. You do that by setting
merge.preferancestor. Mercurial will tell you about it when this makes sense. With the example below, you would see:Mercurial before version 3.0: Lazy Badger is correct that you cannot pick the ancestor picked by Mercurial when using it from the command line. However, you can do it internally and it's not too difficult to write an extension for this:
Put this in a file and load the extension. You can now use
to override the normal ancestor. As you've found out, this does make a difference if there are several possible ancestors. That situation arises if you have criss-cross merges. You can create such a case with these commands:
The graph looks like this:
If you merge normally you get changeset
eb49ad46fd72as the ancestor and the filexcontains:If you instead use
hg merge --ancestor 2you get a different result:In both cases, my KDiff3 were able to handle the merge automatically without reporting any conflicts. If I use the "recursive" merge strategy and pick
e72ddea4d238as the ancestor, then I'm presented with a sensible conflict. Git uses the recursive merge strategy by default.