mercurialmultiple-repositories

How do I check out a mercurial revision from a different repository?


In git if you have two remote repositories setup as default and other and they both contain the cool-feature branch but they get out of sync, you might have something like this:

* <--- HEAD, cool-feature, default/cool-feature
|
|
o another commit
|
|
o commit for awesome
|
|
o <--- other/cool-feature
|
.
.
.

I can jump back and forth by doing a git checkout other/cool-feature and git checkout default/cool-feature.

How do I do the equivalent in Mercurial? Is it even possible?


Solution

  • If you use bookmarks to emulate Git branches and you pull from two repositories where bookmarks have diverged, then one of them will be labeled as name@repo, where name is the bookmark's name and repo is either the identifier in the [paths] section of .hg/hgrc or a unique identifier when there is no such entry.

    However, if the bookmarks haven't diverged, but one revision is the ancestor of another, then you'll only get the most recent one. You can still individually get bookmarks from remote repositories via:

    hg pull -B name repo1
    hg update name
    

    and then:

    hg pull -B name repo2
    hg update name
    

    Alternatively, you can also use hg id to figure out which nodes remote bookmarks correspond to:

    hg update -r $(hg id -i -r name repo1)
    

    or:

    hg update -r $(hg id -i -r name repo2)
    

    Note that you may want to use local tags or additional bookmarks in order to mark the revisions if you plan on switching back and forth frequently, since accessing remote repositories can be a bit slow.

    If this is something that you need frequently, you may want to consider the remotenames extension. Warning: this extension changes the normal behavior of bookmarks quite a bit (making it a lot more Git-like, in fact).