41

How can you clone a Mercurial repository as of a specific changeset?

Ie: If the master repo has changesets 1-10, how can get a copy of the source as it existed in changeset #7?

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

1 Answers1

60

This command tells to use -r / --rev switch:

hg help clone

So :

hg clone -r 7
pastjean
  • 1,307
  • 11
  • 21
  • 4
    Note this will clone the specified revision and all ancestors, but will NOT clone revisions that are not related to the specified revision but come earlier in the source repository's revlog (e.g. old divergent branches). – rationull Feb 12 '14 at 22:04
  • 7
    Note: If you're using bitbucket, you can use the specific hash key from any given commit as the revision number when cloning or pulling from a bitbucket repository. Example, for a user fakeuser, project fakeproject, commit hash a123456: `hg clone https://bitbucket.org/fakeuser/fakeproject -r a123456` – Brian Swift Sep 02 '15 at 21:23
  • @rationull your comment is important. I have typically gotten around that by using a script to do a bunch of "pull"s. Do you know of a better way? I.e. a more complete answer to the OP's question? – markgalassi Mar 01 '16 at 17:13
  • @markgalassi Specifically the OP asked about getting the source as of changeset 7, and the clone command as given does achieve that. I don't know of a way to get all changesets up to the requested one without resorting to writing python code using Mercurial's APIs to look at the actual changesets/revlog in order and push/pull each to the target repo. A co-worker of mine did have to write a script to do that very thing at one point but I don't know the details. – rationull Mar 03 '16 at 00:53