How to merge two branches in Mercurial when there is nothing to merge

前端 未结 2 1106
小鲜肉
小鲜肉 2020-12-23 17:08

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 b

相关标签:
2条回答
  • 2020-12-23 17:35

    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.

    0 讨论(0)
  • 2020-12-23 17:48

    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.

    0 讨论(0)
提交回复
热议问题