简体   繁体   English

如果没有要合并的话,如何在Mercurial中合并两个分支

[英]How to merge two branches in Mercurial when there is nothing to merge

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合并并获得

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. 但是,由于'trunk'分支中没有任何改变,合并表示没有任何合并,这是公平的。 I just need to end up one branch called 'trunk'. 我只需要结束一个名为“trunk”的分支。 How can I do that? 我怎样才能做到这一点?

Merging in Mercurial always work the following way: Mercurial中的合并始终以下列方式工作:

  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. 但是,如果您更新到实验分支,与trunk合并,则合并变更集将在实验分支上。

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: 对于书签,对于较新版本的Mercurial,书签是不可或缺的一部分,如果您更新为书签,请说如下:

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. 在这种情况下,如果在主干分支的头部有一个名为moving-target的书签,并更新到该书签,则合并变更集在提交时将向前移动该书签。

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. 但是,您应该能够将experiment合并到default并实现相同的功能。

If you start with this: 如果你从这开始:

在此输入图像描述

and perform this: 并执行此操作:

hg update trunk
hg merge experiment

you should end up with this: 你应该最终得到这个:

在此输入图像描述

Other options: 其他选择:

Using rebase or a patch queue you could actually relocate the changesets on the experiment branch back on to default . 使用rebase补丁队列,您实际上可以将experiment分支上的变更集重新定位到default This would basically remove the experiment named branch and create a few more default changesets. 这基本上会删除名为branch的experiment并创建一些更多的default更改集。 You cannot do this, however, if you've already shared the changesets form the first image, above, with another user. 但是,如果您已经与另一个用户共享上面第一张图像的更改集,则无法执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM