hg merge preview

Martin Geisler mg at aragost.com
Wed Aug 31 13:06:28 UTC 2011


Peter Toft <pto at linuxbog.dk> writes:

Hejsa :-)

> I often end in a situation, where I need to run "hg merge".
>
> $ hg heads
> changeset:   49:f119521796a0
> tag:         tip
> parent:      47:f92aa8fc1090
> user:        Peter Toft
> date:        Wed Aug 31 14:10:02 2011 +0200
> summary:     stuff
>
> changeset:   48:90ac163c1f15
> user:        Joe Gun
> date:        Wed Aug 31 14:10:10 2011 +0200
> summary:     stuff too :)
>
> It will normally go just fine, but I don't like that I don't have a
> good "preview". I know "hg merge -P", but this does not tell anything
> about potential merge conflicts.
>
> The second option I have is to do a "hg diff" on the two heads
>
>  hg diff -r 49 -r 48 --stat
>  A.txt |  2 +-
>  C.txt |  2 +-
>  D.txt |  1 -
>  3 files changed, 2 insertions(+), 3 deletions(-)
>
> which does give some overview, but not anything like what I would like
> (the format does not matter):
>
>   From changeset 49:
>    Updates: A.txt C.txt
>
>   From changeset 48:
>    Updates: A.txt D.txt
>
>   Merge problem will be found in A.txt when running hg merge
>
> Especially the merge problem identification would be really nice.
>
> Are there better means to analyze the effect of hg merges before doing
> them?

Not really -- to identify the problems you will have to run (simulate)
the merge process. So the best you can do is to do it non-interactively
and then revert back to where you were.

Start the merge with:

  $ hg merge --tool internal:merge

List the status of the merge:

  $ hg resolve --list

Abort the merge with:

  $ hg update -C .

You can wrap all this into a shell alias:

  [alias]
  preview = !$HG -q merge --tool internal:merge $1 &&
             $HG resolve --list &&
             $HG -q update -C .

The $1 in the alias lets you do 'hg preview 10' to see what a merge with
revision 10 will look like.

With Mercurial 1.9 you can use filesets to show only the unresolved
files:

  $ hg locate "set:unresolved()"

after doing the merge. Filesets are described here:

  http://www.selenic.com/mercurial/hg.1.html#filesets

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/



More information about the Mercurial mailing list