【问题标题】:Merging Mercurial branches from separate repositories合并来自不同存储库的 Mercurial 分支
【发布时间】:2011-07-08 09:39:45
【问题描述】:

我正在尝试弄清楚如何将分支从单独的 repo 合并到当前。

我有以下几点:

PJT1 - 包含分支 default 和 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 分支中?

【问题讨论】:

    标签: mercurial branching-and-merging


    【解决方案1】:

    您需要合并,但请记住分支 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 之后,你不会看到foodog,除非你看到hg branches --closed

    这是因为 Mercurial 中的分支永远不会完全消失(一个设计特性),它们通常只保留用于像 release-1.0stable 这样的终身事物。对于像错误和功能这样的短期工作,请考虑使用书签。这是两者的一个很好的比较:http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial

    【讨论】:

      【解决方案2】:

      您也可以尝试使用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。您的问题表明这正是您不想做的,但仍应注意。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多