Merging Mercurial branches from separate repositor

2020-05-17 04:35发布

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?

2条回答
疯言疯语
2楼-- · 2020-05-17 04:53

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

查看更多
太酷不给撩
3楼-- · 2020-05-17 04:55

You could also try using the rebase extension. It would look something like this:

hg fetch -y ../PJT1 -r foodog -m "this is a test"
hg rebase --source <sRev> --dest <dRev>

The rebase action will detatch changeset sRev and all descendents and apply the group of changes to changeset dRev. By default, the changes will be applied on the default branch. So, in your case, sRev would be the first changeset on branch foodog and dRev would be the default changeset you want to apply them to.

Finally, If you want to override this and preserve the source branch name you can use rebase option --keepbranches. Your questions indicates that this is exactly what you do not want to do, but it should still be noted.

查看更多
登录 后发表回答