Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging Mercurial branches from separate repositories

I'm trying to figure out how to merge branches from a separate repo into the current.

I have the following:

PJT1 - contains branches default and foodog

PJT2 - contains branch default

from PJT2, I do the following:

$ hg fetch -y ../PJT1 -r foodog -m "this is a test" 

Now, if I look in PJT2, I see the correct files and changes. However, I if I do hg branches, I get the following:

[someone@myhome pjt2]$ hg branches foodog                         1:c1e14fde816b default                        0:7b1adb938f71 (inactive) 

and hg branch reveals the following:

[someone@myhome pjt2]$ hg branch foodog 

How do I get the contents from PJT1's foodog branch into PJT2's default branch?

like image 904
Paul Avatar asked Mar 03 '11 21:03

Paul


People also ask

How do I merge 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.

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.

What is Mercurial default branch?

Mercurial's main branch is called "default" and is analogous to "trunk" in SVN, "HEAD" in CVS, and "master" in Git. If you try to use some other name for your "main" branch, users will get a more or less random branch when they clone and commit things in the wrong place, which is generally undesirable.


1 Answers

You need to merge, but keep in mind changes on branch foodog will always be on foodog -- branches never go away but they can be hidden. This sequence of commands is as close as you'll get to what you're asking:

cd PJT2 hg update default # just in case you were somewhere else hg pull ../PJT1 -r foodog  # that gets you foodog hg merge foodog  # that merges the changes into default hg commit # commit the merge hg update foodog # go to the most recent change in foodog (note: it is not a 'head') hg commit --close-branch 

After the merge hg branches will still show foodog unless you do hg branches --active which only shows branches that have heads on them. After the commit --close-branch you won't see foodog unless you do hg branches --closed.

It's because branches in Mercurial never go away entirely (a design feature) that they're often reserved only for life-long things like release-1.0 or stable. For short-lived efforts like bugs and features consider using bookmarks instead. Here's a great comparison of the two: http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial

like image 181
Ry4an Brase Avatar answered Sep 23 '22 05:09

Ry4an Brase