How resolve this Mercurial conflict?
Asked Answered
T

2

12

I'm frustrated with Mercurial and Python since it makes easy things difficult. I have a trivial conflict and since Mercurial does not give any suggestion what to do I don't know even how to resolve this trivial file conflict:

KDiff3

The conflict is trivial but if I can't resolve this I can't resolve anything complicated either. Can I just edit the file to a way I want and commit it again from anywhere? Should I run hg merge? Why can't Mercurial even let me choose a version to keep? Why is something trivial near impossible to do without digging through 1000 poorly written manpages?

Tuscan answered 25/1, 2012 at 13:35 Comment(2)
Just for the records, this is not about Mercurial and Python making things difficult but about the usage of the kdiff3 programm ...Virgulate
@Virgulate It is Mercurial blocking the entire workflow for a trivial diff. So it is Mercurial making things difficult. It violates rule number 1: KEEP IT SIMPLE. Today any 8-bit system from 1972 is vastly more efficient than the "smart" systems named git or Mercurial, trying to be smart and blocking the user effectively making it impossible to achieve the simplest task. I wish I had stayed with Windows 95.Tuscan
R
25

You need to look at the KDiff3 documentation, in particular the section on merging and the output window. To resolve the conflict, you need to decide if live or january is the right choice for the line. That decision is yours to make, no tool can know if you meant one or the other.

In KDiff3, you press Ctrl + 2 to select live, press Ctrl + 3 to select january or right-click in the margin of the bottom window and select the line you want. You can also click in the bottom window and edit the line manually.

Mercurial let's you configure your merge tool any way you like. TortoiseHg ships with a default configuration that puts KDiff3 in the top of the list, but you can use another tool if you like. A merge tool is really just a program that accepts four filenames: the three files to compare (base, parent 1, parent 2) and an output file name.

To resolve conflicts on the command-line you need to launch a suitable command-line three-way merge tool. You can for example merge with vim if you like. (I'm afraid I don't know anything about vimdiff, I use KDiff3 myself.)

If you don't like to see merge tools pop up, then you can set

[ui]
merge = internal:merge

to make Mercurial use the internal three-way merger only. It will merge files fine when the edits are not in conflicts. When there is a conflict, the file is marked as "unresolved" and conflict markers are stored in the file.

You then need to edit the file by hand to get the version you want. You can also re-merge and pick either the local (your) version:

$ hg resolve --tool internal:local your-file

or the other version:

$ hg resolve --tool internal:other your-file

You restart the merge completely with hg resolve your-file. The file needs to be marked "resolved" before you can commit it. This is done with hg resolve --mark your-file. See hg resolve --list for the status of the current merge.

Reisch answered 25/1, 2012 at 13:53 Comment(5)
Thank you Martin. I'd also like to be able do resolve at the command line if feasible.Tuscan
You're right though - KDiff3 doesn't have the most intuitive of interfaces. You'll find that it feels very straightforward after a while but it's easy to forget how intimidating the screen looks when it first pops up. By the way, you can also use the "A", "B", and "C" buttons in the toolbar to decide which bit to keep.Declarer
@NickRosencrantz: I've added a bit about how you can configure the merge tool.Reisch
@NickPierpoint: I completely agree — KDiff3 is not a very pretty or intuitive tool and it takes a while to get used to it.Reisch
But once you understand it, it's really the easiest tool there is to see what exactly the conflicts are, and to get the merge result you want. You wonder why anyone would use anything else!Kaufmann
E
22

Base is the previous version in your local system, Parent 1 is your current changes, parent 2 is the file from server.

If you need your changes need to be checked in, select B everywhere in the merge menu. If you want the latest server version in your local machine, select C everywhere in the merge menu

Englut answered 30/5, 2012 at 8:44 Comment(1)
Thank you! How did you know "base" is previous version? Was googling for an hour about mystical and pointless "base", "parent1", "parent2" words, gosh!Violative

© 2022 - 2024 — McMap. All rights reserved.