Mercurial/hg:将更改从分支获取到主干

发布于 2024-11-30 08:21:29 字数 58 浏览 1 评论 0原文

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

Apparently I've checked the last couple of week's commits into a branch. Apart from the changes to one file, I want to commit everything to the trunk. What do I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2024-12-07 08:21:30

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

hg update default
hg merge thebranchname

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

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

When you're talking named branches with Mercurial you're talking about a permanent attribute on a changeset. A changeset cannot be on a different branch and still be the same changeset. You can (as @Matt Ball) suggested merge that branch's result into default:

hg update default
hg merge thebranchname

Or you can go through, crazy, history-destroying contortions to pretend those changes weren't done on a branch (as @Rudi details (sorry)).

Just merge for now, and in the future consider using bookmarks, anonymous branches, or separate clones, for work you don't wnat to push immediately -- none of those make permanent annotations on changesets.

╭ゆ眷念 2024-12-07 08:21:30

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

If you did not push out any of the changesets of the new branch, and have no merges in the branch, you can use the mq extension to move the in trunk unwanted changeset to the tip of the branch.

$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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文