Branch Names and Merging
As you’ve probably noticed, merges in Mercurial are not symmetrical. Let’s say our repository has two heads, 17 and 23. If I hg update to 17 and then hg merge with 23, Mercurial records 17 as the first parent of the merge, and 23 as the second. Whereas if I hg update to 23 and then hg merge with 17, it records 23 as the first parent, and 17 as the second.
This affects Mercurial’s choice of branch name when you
merge. After a merge, Mercurial will retain the branch name of the first
parent when you commit the result of the merge. If your first parent’s
branch name is foo
, and you merge with
bar
, the branch name will still be
foo
after you merge.
It’s not unusual for a repository to contain multiple
heads, each with the same branch name. Let’s say I’m working on the
foo
branch, and so are you. We commit different
changes; I pull your changes; I now have two heads, each claiming to be
on the foo
branch. The result of a merge will be a
single head on the foo
branch, as you might
hope.
But if I’m working on the bar
branch, and I merge work from the foo
branch, the
result will remain on the bar
branch.
$
hg branch
bar$
hg merge foo
1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit)$
hg commit -m 'Merge'
$
hg tip
changeset: 4:00d606298226 branch: bar tag: tip parent: 2:f32855c6764f parent: 3:2e55e6a73143 user: Bryan O'Sullivan <bos@serpentine.com> date: Tue May 05 06:44:26 2009 +0000 summary: Merge
To give a ...
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.