Handling merge conflicts with Mercurial

When you encounter a merge conflict with Mercurial, things can get a little disorienting. The following is a practical list of steps to handle a merge conflict without getting lost.

  1. List the conflict status (U = Unresolved, R = Resolved):
    hg resolve -la
  2. Check the parents (first parent = local, second parent = other):
    hg parents
  3. Resolve the conflict:
    1. Manual resolution and mark as resolved:
      vim <file>
      hg resolve -m <file>
    2. Resolution using a tool (such as fmmerge):
      hg resolve -t fmmerge <file>
    3. Resolve by selecting local/other version:
      hg resolve -t internal:local <file>
      hg resolve -t internal:other <file>
  4. (If the resolution went wrong) Marking a file as unresolved, to redo the merge:
    hg resolve -u <file>
  5. (If you decide the merge was a bad idea) To abort the merge altogether:
    hg update -C <rev>

One thought on “Handling merge conflicts with Mercurial

  1. Pingback: Handling merge conflicts with git | Keep It With Mine

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>