19

Is there any way to take complete manual control over the merge process in Mercurial?

I want to be able to choose direction of file-merge, even for files without conflicts. Is that possible?

sholsinger
  • 3,028
  • 2
  • 23
  • 40
Jox
  • 7,132
  • 14
  • 49
  • 63

4 Answers4

20

Turn "pre-merge" off in your merge configuration. Then everything counts as a conflict and you can pick "left" or "right" for each and every file change.

[merge-tools]
mymergetool.premerge = False

from MergeToolConfiguration on the Mercurial wiki.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • Nowaways you might try `hg merge --tool internal:prompt` – Ry4an Brase Apr 12 '12 at 01:34
  • Probably it would help somebody because nor snippet above neither below didn't help me. I've added `[ui] -> merge = internal:merge` and it completely disabled resolving tools after failed merge. Actually [this](http://i.stack.imgur.com/WNHq4.png) annoying tool started appearing after I've updated my Mercurial version. – ivkremer Oct 29 '15 at 09:55
12

Edit your configuration file this way:

[ui]
merge = kdiff3

[merge-tools]
kdiff3.premerge = false
kdiff3.args=--L1 base --L2 local --L3 other $base $local $other -o $output

By default it puts the --auto argument on kdiff3 so kdiff3 auto merges.

Eduardo
  • 5,645
  • 4
  • 49
  • 57
  • +1 because I'm struggling with this for half hour, and you are the first person to recommend removing the `--auto` argument. It would take me forever to find it (as I already missed it all other times I needed a manual merge). – Denilson Sá Maia Oct 01 '11 at 23:11
2

A merge is always performed between the working directory's parent revision and another revision, by default the other head in your repository.

If you want to merge in the other "direction" you can change which branch is in your working directory by checking out a specific revision:

hg update -r [rev]

To see which heads you have in your repository run the following command:

hg heads

Alternatively, if you're using fetch you can use the --switch-parent option to merge in the other direction:

hg fetch --switch-parent

You can't change the direction of the merge on a file-by-file basis as Mercurial works with changesets which affect a whole repository not by tracking changes on to individual files like CVS.

David Webb
  • 190,537
  • 57
  • 313
  • 299
  • 1
    I see he accepted your answer, but I don't think it's actually what he was asking. You told him how to pick "left" or "right" for all non-conflicts, but if he wants to mix-and match he needs to turn the internal "pre-merge" off before launching his merge tool. – Ry4an Brase Apr 02 '09 at 04:59
1

In case of KDiff3 it is vital to add option --qall (see http://kdiff3.sourceforge.net/doc/documentation.html). There will be an automatic merge of some conflicts without this key (like "Automatically Solve Simple Conflicts" from "Merge" menu). Thus the more proper command line is:

[ui]
merge = kdiff3

[merge-tools]
kdiff3.premerge = False
kdiff3.args=$base $local $other -o $output --L1 base --L2 local --L3 other --qall
Nikita
  • 191
  • 1
  • 4