Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does merge direction matter in Mercurial?

Take a simple example: I'm working on the default branch, have some changesets committed locally, and I pulled a few more from the master repository. I've been working for a few days in my isolated local repository, so there's quite a few changes to merge before I can push my results back into master.

default ---o-o-o-o-o-o-o-o-o-o-o  (pulled stuff)
            \
             o----o------------o  (my stuff)

I can do two things now.

Option #1:

hg pull
hg merge

Result #1:

default ---o-o-o-o-o-o-o-o-o-o-o
            \                   \
             o----o------------o-O

Option #2:

hg pull
hg update
hg merge

Result #2:

default ---o-o-o-o-o-o-o-o-o-o-o-O
            \                   /
             o----o------------o

These two results look isomorphic to me, but in practice it seems that option #2 results in way smaller changesets (because it only applies my few changes to the mainline instead of applying all the mainline changes to my few).

My question is: does this matter? Should I care about the direction of my merges? Am I saving space if I do this? (Doing hg log --patch --rev tip after the merge suggests so.)

like image 934
Lóránt Pintér Avatar asked Feb 09 '11 15:02

Lóránt Pintér


People also ask

Does it matter which branch you merge from?

Usually it does not matter if both branches are topic or feature branches. However, if you have an integration branch or a branch that marks what's been published, you definitely want to use the long lived integration branch as the one that's checked out and merge the other one into it.

Does merge order matter?

The only difference that comes from merging order should be the order of the parents of the merge commit. Edit: If you are interested in more details, torek's answer is what you are looking for.

How do you combine two mercurial heads?

To start a merge between the two heads, we use the hg merge command. We resolve the contents of hello. c This updates the working directory so that it contains changes from both heads, which is reflected in both the output of hg parents and the contents of hello.

How do I merge two branches in mercurial?

To merge two branches, you pull their heads into the same repository, update to one of them and merge the other, and then commit the result once you're happy with the merge. The resulting changeset has two parents.


1 Answers

They're (effectively) identical. You see a difference in the hg log --patch --rev X output size because log shows the diff of the result and (arbitrarily) its 'left' parent (officially p1), but that's not how it's stored (Mercurial has a binary diff storage format that isn't patch/diff based) and it's now how it's computed (p1, p2, and most-recent-common-ancestor are all used).

The only real difference is, if you're using named branches, the branch name will be that of the left parent.

like image 180
Ry4an Brase Avatar answered Sep 28 '22 04:09

Ry4an Brase