这是设计使然。导入的 Git 分支仅在 Mercurial 中进行标记,并且hg heads
应该给你正确数量的导入“分支”。
正如中提到的这个线程 http://www.selenic.com/pipermail/mercurial/2007-December/016061.html:
考虑一棵看起来像这样的树:
o-o-o-o-o-o-b <- branch foo
/
-o-o-a
\
o-o-c <- branch bar
“a”及其祖先在哪个分支上?
我们没有丝毫线索。事实上,我们唯一确定的变更集是 b 和 c,因为分支名称不是历史的一部分。
So:
事实证明,实际上不可能正确地做到这一点,因为 git 没有存储足够的信息。
考虑一个 git 中有两个分支的存储库,每个分支都有多个提交。
由于 git 不记录每个提交源自哪个分支,因此树中没有足够的信息来标记每个变更集。
git 用户可以交换两个分支的名称,并且不会记录任何内容表明它曾经不同。如果两个分支有一个共同的祖先(而且几乎肯定会有),
该祖先在哪个分支上?我们不知道。
在一般情况下,我们能做的最好的事情就是将每个分支头标记为位于该分支上。然后,如果您进行增量转换,我们可能会做正确的事情。但是 git 的分支概念与 hg 的概念并不完美匹配,因此这种转换也不会是完美的。
您可以使用小型 Git 存储库(Git 1.6.5.1、Hg1.3.1)来测试它:
PS C:\Prog\Git\tests> cd .\hgimport
PS C:\Prog\Git\tests\hgimport> git init gitRepoToImport
PS C:\Prog\Git\tests\hgimport> cd .\gitRepoToImport
PS [...]\gitRepoToImport> echo firstContentToBr1 > br1.txt
PS [...]\gitRepoToImport> echo firstContentToBr2 > br2.txt
PS [...]\gitRepoToImport> echo firstContentToBr3 > br3.txt
PS [...]\gitRepoToImport> git add -A
PS [...]\gitRepoToImport> git commit -a -m "first content, to be evolved in three different branches"
在三个独立的分支中进行大量修改:
PS [...]\gitRepoToImport> git checkout -b br1
PS [...]\gitRepoToImport> echo firstEvolutionInBr1 >> .\br1.txt
PS [...]\gitRepoToImport> git commit -a -m "first evolution in branch 1"
PS [...]\gitRepoToImport> echo secondEvolutionInBr1 >> .\br1.txt
PS [...]\gitRepoToImport> git commit -a -m "second evolution in branch 1"
PS [...]\gitRepoToImport> git checkout master
PS [...]\gitRepoToImport> git checkout -b br2
PS [...]\gitRepoToImport> echo firstEvolutionInBr1 >> .\br2.txt
PS [...]\gitRepoToImport> git commit -a -m "first evolution in branch 2"
PS [...]\gitRepoToImport> git checkout master
PS [...]\gitRepoToImport> git checkout -b br3
PS [...]\gitRepoToImport> echo firstEvolutionInBr3 >> .\br3.txt
PS [...]\gitRepoToImport> git commit -a -m "first evolution in branch 3"
PS [...]\gitRepoToImport> echo secondEvolutionInBr3 >> .\br3.txt
PS [...]\gitRepoToImport> git commit -a -m "second evolution in branch 3"
PS [...]\gitRepoToImport> echo thirdEvolutionInBr3 >> .\br3.txt
PS [...]\gitRepoToImport> git commit -a -m "third evolution in branch 3"
PS [...]\gitRepoToImport> git checkout br2
PS [...]\gitRepoToImport> echo secondEvolutionInBr2 >> .\br2.txt
PS [...]\gitRepoToImport> git commit -a -m "second evolution in branch 2"
PS [...]\gitRepoToImport> git checkout br1
PS [...]\gitRepoToImport> echo thirdEvolutionInBr3 >> .\br1.txt
PS [...]\gitRepoToImport> git commit -a -m "third evolution in branch 1"
PS [...]\gitRepoToImport> git checkout br2
PS [...]\gitRepoToImport> echo thirdEvolutionInBr3 >> .\br2.txt
PS [...]\gitRepoToImport> git commit -a -m "third evolution in branch 2"
然后克隆该 Git 存储库(以防万一,以进行其他测试)
PS [...]\gitRepoToImport> cd ..
PS C:\Prog\Git\tests\hgimport> git clone .\gitRepoToImport gitRepoToImport1
Configure your ~/.hgrc
with a format UTF-8
without BOM (took me a while to get it right!)
[extensions]
hgext.convert =
然后进行转换
PS C:\Prog\Git\tests\hgimport> hg convert .\gitRepoToImport1 hgRepo
PS C:\Prog\Git\tests\hgimport> cd .\hgRepo
PS C:\Prog\Git\tests\hgimport\hgRepo> hg heads
您将得到三个预期的“分支”
changeset: 9:ad0884395ada
tag: tip
user: VonC
date: Mon Nov 16 21:45:35 2009 +0100
summary: third evolution in branch 2
changeset: 6:854bc6537c7c
user: VonC
date: Mon Nov 16 21:45:19 2009 +0100
summary: third evolution in branch 1
changeset: 3:9194cf25d3ca
user: VonC
date: Mon Nov 16 21:44:09 2009 +0100
summary: third evolution in branch 3