7

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. 
Community
  • 1
  • 1
Industrial
  • 41,400
  • 69
  • 194
  • 289

2 Answers2

14

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.

ruipacheco
  • 15,025
  • 19
  • 82
  • 138
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • Oh. So I need to run `hg update feature1 && hg merge feature2` and so on for every feature descending from the `dev-1.1`-revision? – Industrial Feb 06 '12 at 11:04
  • 1
    Merging `feature1` and `feature2` is a different matter. But yes, when the features are made in parallel (like in your case), then you need to merge them into your `dev-1.1` track. If you only had `feature1`, then there's no parallel development going on and so `hg update` is the right answer. – Martin Geisler Feb 06 '12 at 11:18
  • It doesn't help that (at least in mercurial 2.7), `hg merge --preview feature1` will list all the appropriate changesets... but then the actual merge will still give the error discussed here. – Ti Strga Feb 11 '14 at 21:17
  • @TiStrga: That is because `hg merge --preview REV` does nothing but show you `hg log -r '::REV - ::.'`. That is, it shows you ancestors of the revision you merge with that are not already an ancestor of the working copy parent revision. Maybe we should abort instead of showing that when `REV` is not a valid revision to merge with. – Martin Geisler Feb 12 '14 at 12:49
  • Is there any alternative to `hg update feature2; hg bookmark -f dev-1.1` to "merge" in feature2 rather than feature1? (That is, to update but also advance the dev-1.1 bookmark.) – Robert Tupelo-Schneck Jan 12 '17 at 19:05
3

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
jpsecher
  • 4,461
  • 2
  • 33
  • 42