Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging bookmarks in mercurial

After asking this question yesterday about branching in mercurial, I've decided to try out bookmarks for short-lived branches (features), as shown below.
However now when I am trying to merge my bookmarked heads together into the development revision, I get below error:

hg update dev-1.1
hg merge feature1
abort: nothing to merge

What am I doing wrong?

Graphical representation of my repo:

o  changeset:   5:fa2b19961b46
|  bookmark:    feature1
|  description:  Work on feature 1 finished.
|
| o  changeset:   4:6ea0155d4d89
| |  bookmark:    feature2
| |  description: Work on feature 2 started. 
| |
o |  changeset:   3:44e335b5426c
| |  bookmark:    feature1
|/   description: Work on feature#1 started.
|
@    changeset:    2:407b3b94624f
|    tag:          dev-1.1
|    description:  Development for release 1.1 started. 
like image 205
Industrial Avatar asked Feb 06 '12 10:02

Industrial


2 Answers

Like it says, there is nothing to merge — you should use update instead:

$ hg update feature1

You can only merge divergent parts of history, and here the dev-1.1 changeset is simply an ancestor of the feature1 changeset. Mercurial 2.1 says

$ hg merge feature1
abort: nothing to merge
(use 'hg update' or check 'hg heads')

in this case and we hope this will make the error clearer.

If you had bookmarked the dev-1.1 changeset (instead of tagging it), then a plain

$ hg update

will now (with Mercurial 2.1) result in an update of the dev-1.1 bookmark. So if you start with

$ hg bookmarks
 * dev-1.1                   0:b1163a24728f
   feature1                  3:c84f04513651
   feature2                  2:e60dd08af282

and then update:

$ hg update
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
updating bookmark dev-1.1

then the bookmark is updated:

$ hg bookmarks
 * dev-1.1                   3:c84f04513651
   feature1                  3:c84f04513651
   feature2                  2:e60dd08af282

With earlier versions, you would have to do

$ hg update feature1
$ hg bookmark -f dev-1.1

This still applies if a plain hg update doesn't take you to the right changeset, e.g., if you had wanted to "merge" with feature2 instead.


The idea of using merge when history hasn't really diverged comes from Git. In that system, there is a notion of a fast-forward merge, which is what we call an update in Mercurial.

like image 109
Martin Geisler Avatar answered Sep 22 '22 02:09

Martin Geisler


If the changesets have been made public, you can force Mercurial to do a merge if you want to insist on having each feature as a merge in the repository:

$ hg update feature1
$ hg debugsetparents dev-1.1 feature1
$ hg commit -m 'Feature 1 reviewed by me.'
$ hg bookmark -d feature1

If the changesets have not been made public, you can collapse the changesets into one:

$ hg update feature1
$ hg rebase --dest dev-1.1 --collapse
$ hg bookmark -d feature1
like image 21
jpsecher Avatar answered Sep 23 '22 02:09

jpsecher