Mercurial/hg:将更改从分支转移到主干



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

当您使用Mercurial谈论命名分支时,您正在谈论更改集中的永久属性。变更集不能位于不同的分支上,但仍然是相同的变更集。你可以(如@Matt Ball)建议合并该分支的结果到默认值:

hg update default
hg merge thebranchname

或者你可以通过疯狂的,破坏历史的扭曲来假装这些更改没有在分支上完成(如@Rudi details(抱歉))。

现在就合并,将来考虑使用书签,匿名分支,或者单独的克隆,对于你不想立即推送的工作——这些都不会在更改集上做永久的注释。

如果您没有推出新分支的任何更改集,并且分支中没有合并,则可以使用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

最新更新