当没有什么可合并时如何合并 Mercurial 中的两个分支

发布于 2024-11-02 17:04:51 字数 370 浏览 0 评论 0原文

我是 Mercurial 的新手,我正在尝试做一些非常简单的事情,但不知道如何做。我创建了一个分支来进行一些实验,而不干扰主分支。

trunk       A -- B -- C
                       \
experiment              D -- E -- F

我喜欢这个实验的进行方式,并希望将其与 trunk 合并并获取

trunk       A -- B -- C -- D -- E -- F

但是,由于“trunk”分支中没有任何更改,因此合并表示没有任何内容可以合并,这很公平。我只需要结束一个名为“主干”的分支。我怎样才能做到这一点?

I'm new to mercurial and I'm trying to do something really simple but can't figure out how to. I created a branch to do some experimentation without disturbing the main branch.

trunk       A -- B -- C
                       \
experiment              D -- E -- F

I like how the experiment went and want to merge it with trunk and get

trunk       A -- B -- C -- D -- E -- F

However, since nothing was changed in the 'trunk' branch, the merge says that there is nothing to merge, which is fair enough. I just need to end up one branch called 'trunk'. How can I do that?

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

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

发布评论

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

评论(2

泪意 2024-11-09 17:04:51

Mercurial 中的合并始终按以下方式进行:

  1. 更新到其中一个分支(请参阅下面的注释,了解为什么您要选择一个或另一个分支,而不仅仅是选择一个随机分支)
  2. 与另一个分支合并

例如,在您的情况下,您会做:

hg update trunk
hg merge experiment

选择要更新的正确分支

在选择要更新到哪个分支以及从哪个分支进行合并时需要考虑一些事项,这与书签和分支名称有关。

先取分支名称。如果您首先更新到主干分支,然后与实验合并,则合并变更集将位于主干分支上。

但是,如果您更新到实验分支,并与主干合并,则合并变更集将位于实验分支上。

在考虑合并原因时,这一点很重要。您是否将实验合并到主干中,或者是否使用主干上发生的其他更改来更新实验。

至于书签,对于较新版本的 Mercurial,书签是不可或缺的一部分,如果您更新到书签,请像这样说:

hg update moving-target

然后提交,该书签将跟随您的提交,即。它会继续前进。

因此,如果您在主干分支的头部有一个名为 moving-target 的书签,并更新到该书签,则当您提交合并变更集时,该书签将向前移动。

Merging in Mercurial always work the following way:

  1. Update to one of the branches (see notes below for why you want to pick one or the other and not just pick a random branch)
  2. Merge with the other branch

For instance, in your case, you would do:

hg update trunk
hg merge experiment

Choosing the right branch to update to

There are some things to consider when picking which branch to update to, and which to merge from, and it has to do with bookmarks and branch names.

Take branch names first. If you first update to the trunk branch, then merge with experiment, the merge changeset will be on the trunk branch.

However, if you update to the experiment branch, merge with trunk, then the merge changeset will be on the experiment branch.

This is important to consider when thinking about why you're merging. Are you merging the experiment into trunk, or are you updating the experiment with other changes having occured on trunk.

As for bookmarks, with newer versions of Mercurial, bookmarks are an integral part, and if you update to a bookmark, say like this:

hg update moving-target

and then commit, that bookmark will follow your commit, ie. it will move forward.

In line of this, if you have a bookmark called moving-target on the head of the trunk branch, and update to that bookmark, the merge changeset, when you commit it, will move that bookmark forward.

自此以后,行同陌路 2024-11-09 17:04:51

创建分支后,您无法完全实现单个默认分支(有一些例外,请参见下文)。但是,您应该能够将 experiment 合并到 default 中并实现相同的效果。

如果您以此开始:

在此处输入图像描述

并执行此操作:

hg update trunk
hg merge experiment

您最终应该得到以下结果:

在此处输入图像描述

其他选项:

使用 变基补丁队列< /a> 您实际上可以将 experiment 分支上的变更集重新定位回 default。这基本上会删除experiment命名分支并创建更多default变更集。但是,如果您已经与其他用户共享了上面第一张图片中的变更集,则无法执行此操作。

Once you've created a branch, you can't exactly achieve a single default branch (with some exceptions, see below). However, you should be able to merge experiment into default and achieve the same thing.

If you start with this:

enter image description here

and perform this:

hg update trunk
hg merge experiment

you should end up with this:

enter image description here

Other options:

Using rebase or a patch queue you could actually relocate the changesets on the experiment branch back on to default. This would basically remove the experiment named branch and create a few more default changesets. You cannot do this, however, if you've already shared the changesets form the first image, above, with another user.

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