107

When merging conflicting changes using hg merge, Mercurial inserts a set of markers into the files to be merged in my working copy like this:

<<<<<<< local
  version = 0.2
=======
  version = 0.1
>>>>>>> other

Then I manually edit all files marked as U from a list produced by hg resolve --all -l and then I tell mercurial I have resolved them by hg resolve -m file1 file2 file3 ...

In many situations I would like however accept either my-only or their-only changes on some conflicting files. I am thinking to create two simple sed/awk/whatever scripts named accept-theirs.sh and accept-my.sh or is there any "proper" way to do it?

chepner
  • 497,756
  • 71
  • 530
  • 681
psihodelia
  • 29,566
  • 35
  • 108
  • 157

2 Answers2

187

Use

hg resolve -t internal:other --all

to accept theirs and

hg resolve -t internal:local --all

to accept yours

Noffls
  • 5,397
  • 2
  • 29
  • 36
  • Thank you very much! I don't understand what @djc means, but your solution works like a charm. – psihodelia Mar 21 '13 at 15:05
  • @psihodelia djc said pretty much the same, try `hg help merge-tools` (mergetools is an alias in latter versions) – MGP Mar 21 '13 at 21:14
  • 6
    As a side note, I aliased this: `[alias] mine = resolve -t internal:local theirs = resolve -t internal:other` –  May 05 '13 at 16:33
  • 1
    Those are three lines to add to one's own `.hgrc`, for the newbies: `[alias]`, then `mine = resolve -t internal:local`, then `theirs = resolve -t internal:other`. After that you can use `hg mine some_file.py` or `hg theirs -a` (for All) – Tobia Apr 04 '14 at 16:28
  • 4
    As of https://phab.mercurial-scm.org/D4379, you may also need to include the `--re-merge` flag (e.g. `hg resolve -t internal:other --re-merge --all`) – Ethan Koenig Nov 27 '19 at 01:06
26

Try this:

hg merge --tool internal:other

See also hg help merge-tools for more information.

Clonkex
  • 3,373
  • 7
  • 38
  • 55
djc
  • 11,603
  • 5
  • 41
  • 54