Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How resolve this Mercurial conflict?

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?

like image 819
Niklas Rosencrantz Avatar asked Jan 25 '12 13:01

Niklas Rosencrantz


2 Answers

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.

like image 95
Martin Geisler Avatar answered Sep 19 '22 17:09

Martin Geisler


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

like image 45
FreeBird Avatar answered Sep 20 '22 17:09

FreeBird