shengy
shengy

Reputation: 9749

How can I clone to the revision without losing the revision number?

I have a repository which has two branches, default and BranchA. The graph is kind of like this:

default rev10 (Node: aaaaa)
default rev9 (Node: bbbbb)
default rev8
------------------BranchA rev7
------------------BranchA rev6
------------------BranchA rev5
default rev4
default rev3
default rev2
default rev1

Then I found out that I want to clone the repository to revision 9, so I cloned it using "Clone to revision" function. And fills the revision number as: bbbbb.

When I open the new repository, BranchA's information is not in it. The repository's graph looks like this:

default rev6 (Node: bbbbb)
default rev5
default rev4
default rev3
default rev2
default rev1

Can I get my old revision number back? Where is the branch information?

Upvotes: 2

Views: 106

Answers (2)

Martin Geisler
Martin Geisler

Reputation: 73798

Revision numbers are local to a given repository. They simply tell you the order of the changesets in the repository — if you have 6 changesets, then they must be numbered 0–5. Mercurial cannot "invent" extra revision numbers to keep the original revision numbers intact.

The reason that revision numbers are local is the distributed nature of Mercurial. Let's say we both have the second repository above with 6 changesets. If I create a new changeset, then it will be number 7 in my repository. Mercurial just picks the next integer.

If you also create a changeset, then you will also get number 7. Now, if I pull from you, then your number 7 will be my number 8 — the revision number changes. This is why you should only use the globally unique changeset hashes when communicating with others. They stay the same after push/pull.

The changeset hashes are really 40 hexadecimal characters: they are 160 bit SHA-1 hash values. Mercurial will normally only show the first 12 characters, unless you add --debug. You can use a prefix of any size to specify the changeset, so any of

$ hg log -r 41453d55b481ddfcc1dacb445179649e24ca861d # full
$ hg log -r 41453d55b481                             # normal
$ hg log -r 41453d                                   # smaller

will do the same. The prefix only has to be unique in the repository and 12 characters is normally enough to ensure that. It is the 12 character hash value that you will want to refer to when talking to colleagues ("can you pull 41453d55b481 and test again?") or when writing release notes ("the bug was fixed in 41453d55b481").

In a tool like TortoiseHg, you can use ViewGoto revision to jump to a changeset using its hash.

Upvotes: 2

Ringding
Ringding

Reputation: 2856

When you supply a revision to the hg clone command, it pulls only this changeset and all its ancestors into the new repository as a new head. Without a revision argument, all changesets will be cloned, and the numbering is also preserved. You can then get rid of rev10 by using hg strip.

Upvotes: 2

Related Questions