【问题标题】:Mercurial/hg: get changes out of branch and into trunkMercurial/hg:将更改从分支中取出并放入主干
【发布时间】:2011-08-20 14:47:44
【问题描述】:

显然我已经检查了过去几周的提交到一个分支。除了对一个文件的更改之外,我还想将所有内容提交到主干。我该怎么办?

【问题讨论】:

  • 将分支合并到主干是一个可接受的解决方案吗?
  • @Matt - 是的,我想会的。我只是这样做了,但是当我必须手动合并我的配置文件时,我会付费。

标签: mercurial merge


【解决方案1】:

当您与 Mercurial 谈论 命名分支 时,您谈论的是变更集上的永久属性。一个变更集不能在不同的分支上并且仍然是相同的变更集。您可以(如@Matt Ball)建议将该分支的结果合并为默认值:

hg update default
hg merge thebranchname

或者您可以通过疯狂的、破坏历史的扭曲来假装这些更改不是在分支上完成的(如@Rudi 详细信息(抱歉))。

暂时只合并,将来考虑使用书签、匿名分支或单独的克隆,用于您不想立即推送的工作——这些都不会对变更集进行永久注释。

【讨论】:

    【解决方案2】:

    如果您没有推出新分支的任何变更集,并且分支中没有合并,您可以使用 mq 扩展将主干中不需要的变更集移动到分支的顶端。

    $EDITOR ~/.hgrc
    [extensions]
    mq =
    «save+quit»
    # import all revisions up to the unwanted rev into a patch queue
    hg qimport -r$BRANCH_TIP_REVISION:$IN_TRUNK_UNWANTED_REVISION
    
    # edit the order of the patches, so that the unwanted patch is the last patch
    $EDITOR .hg/patches/series
      «Move the in trunk unwanted patch to the last line of the file»
    # Variant 1: don't change the branch
    hg qpush -a    # apply all patches
    hg qfinish -a  # finish all patches to regular hg changesets
    hg log -l2     # find out the revision number of the latest revision you want in trunk
    hg up -r trunk # checkout trunk
    hg merge -r $LATEST_WANTED_REVISION_NUMBER # merge only the wanted changesets
    
    # Variant 2: *All* patches are on the new branch, and
    # you want only the differing changeset on the new branch
    hg up -r trunk # move the working copy to trunk
    hg qpush -a    # apply all patches
    hg qpop        # unapply the unwanted one
    hg qfinish     # finish the applied patches
    hg branch $OLD_BRANCH_NAME # switch the working copy to the new branch
                               # if there is already another branch of this name,
                               # you need to checkout the other branch, apply the
                               # patch and merge trunk into that branch afterwards.
    hg qpush       # apply the branch-specific patch
    hg qfinish -a  # finish the patch
    

    【讨论】:

    • 有趣的是,涉及 MQ 的解决方案总是以复杂的多步骤过程结束:)
    • 由于 hg 遵循“如果没有必要,不要重写历史”的原则,因此 hg 故意不让它特别容易做到。重写历史以重新排序涉及分支的任意变更集是相当大的手术。使用 MQ 实际上使这个过程更不容易出错。
    猜你喜欢
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 2014-08-28
    • 2014-01-21
    相关资源
    最近更新 更多