如何克隆到修订版本而不丢失修订版本号?
我有一个存储库,它有两个分支:default
和 BranchA
。该图有点像这样:
default rev10 (Node: aaaaa)
default rev9 (Node: bbbbb)
default rev8
------------------BranchA rev7
------------------BranchA rev6
------------------BranchA rev5
default rev4
default rev3
default rev2
default rev1
然后我发现我想将存储库克隆到修订版 9,因此我使用“克隆到修订版”功能来克隆它。并将修订号填写为:bbbbb
。
当我打开新存储库时,BranchA
的信息不在其中。存储库的图表如下所示:
default rev6 (Node: bbbbb)
default rev5
default rev4
default rev3
default rev2
default rev1
我可以拿回我的旧版本号吗?哪里有分行信息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您为
hg clone
命令提供修订时,它仅将此变更集及其所有祖先拉入新存储库作为新头。如果没有修订参数,所有变更集都将被克隆,并且编号也会保留。然后,您可以使用hg strip
摆脱 rev10。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 usinghg strip
.修订号是给定存储库的本地版本号。它们只是告诉您存储库中变更集的顺序 - 如果您有 6 个变更集,那么它们必须编号为 0-5。 Mercurial 无法“发明”额外的修订号来保持原始修订号完整。
修订号是本地的原因是 Mercurial 的分布式特性。假设我们都有上面的第二个存储库,其中包含 6 个变更集。如果我创建一个新的变更集,那么它将在我的存储库中排在第 7 号。 Mercurial 只是选择下一个整数。
如果您还创建了一个变更集,那么您将也获得编号 7。现在,如果我从您那里提取,那么您的编号 7 将是我的编号 8 - 修订号发生变化。这就是为什么您在与他人通信时应该只使用全局唯一的变更集哈希。推/拉后它们保持不变。
变更集哈希实际上是 40 个十六进制字符:它们是 160 位 SHA-1 哈希值。 Mercurial 通常只会显示前 12 个字符,除非您添加
--debug
。您可以使用任何大小的前缀来指定变更集,因此任何一个都会执行相同的操作。前缀只需在存储库中唯一,通常 12 个字符就足以确保这一点。这是您在与同事交谈时(“您可以提取 41453d55b481 并再次测试吗?”)或编写发行说明(“该错误已在 41453d55b481 中修复”)时需要参考的 12 个字符哈希值。
在像 TortoiseHg 这样的工具中,您可以使用 View → Goto revision 使用其哈希值跳转到变更集。
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 ofwill 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 View → Goto revision to jump to a changeset using its hash.