从不同的代码库合并Mercurial分支

30
我想弄清楚如何将其他仓库的分支合并到当前仓库。 我有以下内容:
PJT1 - 包含默认分支和foodog分支
PJT2 - 包含默认分支
从PJT2开始,我执行以下操作:
$ hg fetch -y ../PJT1 -r foodog -m "this is a test"

现在,如果我查看PJT2,我可以看到正确的文件和更改。 但是,如果我运行hg branches命令,我得到了以下输出:

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

执行hg branch命令后,你将看到以下内容:

[someone@myhome pjt2]$ hg branch
foodog

我如何将PJT1的foodog分支内容合并到PJT2的default分支中?

2个回答

54

您需要合并代码,但要记住分支foodog上的更改始终在foodog分支上 -- 分支永远不会消失,但它们可以被隐藏。这些命令序列是最接近您所需求的:

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
在合并后,hg branches 仍会显示foodog,除非您使用 hg branches --active 命令,该命令只显示有头的分支。 在执行 commit --close-branch 命令之后,除非您使用 hg branches --closed 命令,否则将看不到 foodog
这是由于 Mercurial 中的分支永远不会完全消失(这是一种设计特性),因此它们通常仅用于像release-1.0stable等终身项目。 对于短期任务(如错误和功能),请考虑使用书签代替。 这里有一个关于这两者的很好的比较:http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial

0

您也可以尝试使用rebase扩展程序。它的使用方式类似于:

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

Rebase操作将分离变更集sRev及其所有后代,并将一组变更应用于变更集dRev。默认情况下,这些变更将应用于默认分支。因此,在您的情况下,sRev将是分支foodog上的第一个变更集,而dRev将是您想要将它们应用于的default变更集。

最后,如果您想覆盖此设置并保留源分支名称,则可以使用rebase选项--keepbranches。您的问题表明这正是您不想做的事情,但仍应注意到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接