Mercurial/hg:如何将分支中的更改合并到主干中

3

看来我已经把过去几周的提交检查到了一个分支中。除了对一个文件的更改之外,我想将一切提交到主干中。我该怎么做?


3
将分支合并到主干是否是可行的解决方案? - Matt Ball
@Matt - 是的,我认为是这样。我刚刚做了这件事,但当我不得不手动合并我的配置文件时,我会付出代价。 - Marcin
2个回答

6

当你在使用Mercurial时谈到“命名分支”,你是指变更集上的永久属性。变更集不能位于不同的分支上,仍然保持相同的变更集。您可以像@Matt Ball建议的那样将该分支的结果合并到默认分支中:

hg update default
hg merge thebranchname

或者你可以通过疯狂的历史毁灭扭曲来假装这些更改不是在分支上完成的(如@Rudi详细说明的那样(抱歉))。

现在只需合并,将来考虑使用书签、匿名分支或单独克隆来处理你不想立即推送的工作--这些都不会对变更集进行永久注释。


1

如果您没有推出新分支的任何更改集,并且在该分支中没有合并,则可以使用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的解决方案总是变成了一个复杂的、多步骤的过程 :) - Remy Blank
1
由于hg遵循“不重写历史,除非确实必要”的原则,因此hg故意不会让这个过程变得特别容易。重新编写历史以重新排序涉及分支的任意变更集是相当大的手术。使用MQ实际上使这个过程变得更加不容易出错。 - Ned Deily

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