Search code examples
mergemercurialvimdiff

Unable to resolve hg merge conflict when using vimdiff


I am using the default version of mercurial without much modifications. By default it uses "vimdiff" for the purpose which I wasn't familiar with. I am going to explain the situtation:

After 1st commit on default branch:

#include <stdio.h>

int main

After 1st commit on xyz branch:

#include <stdio.h>

int main()
{
    return 0;
}

After 2nd commit on default branch:

#include <stdio.h>

#define MAX(x, y)     (x > y ? x : y)

int main

Expected code after merging xyz branch into default branch:

#include <stdio.h>

#define MAX(x, y)     (x > y ? x : y)

int main()
{
    return 0;
}

In what way should I accept/discard hunks/diffs/parts of code to obtain the expected result either in vimdiff or ediff. If there is an alternative way to solve this problem then please share.

enter image description here


Solution

  • Mercurial has a set of default mergetools it will search for. If it proposes vimdiff, it is because either it doesn't find any other tool or because you have specified it in your $HOME/.hgrc.

    The page https://www.mercurial-scm.org/wiki/MergeToolConfiguration and hg help mergetool explain the syntax to use to specify a mergetool. I suggest to use KDiff3, which is a cross-platform GUI merge tool.

    Then you have to get familiar with the KDiff3 usage, but it is a GUI so you can just explore it. It also has many keyboard shortcuts if one wants to use them.