我在git存储库中有许多分支:
david@Panama ~/app: git branch -r
origin/HEAD -> origin/master
origin/master
origin/newButtons
origin/newFonts
origin/serverView
如果我尝试将此git repo导入mercurial:
david@Panama ~/: hg convert app
...
david@Panama ~/app-hg: hg update
388 files updated, 0 files merged, 0 files removed, 0 files unresolved
david@Panama ~/app-hg: hg branches
default 1148:6d04af619607
似乎分支已经“丢失”(就它们不再分离而言)并且确实合并到了提示中:
david@Panama ~/app-hg: hg log
changeset: 1148:6d04af619607
tag: tip
user: convert-repo
date: Mon Nov 16 17:57:06 2009 +0000
summary: update tags
changeset: 1147:742e7a01a6c9
parent: 1144:bff259181b22
user: user1
date: Sat Nov 14 17:47:09 2009 +0000
summary: Playing around with fonts to get a cleaner look
changeset: 1146:162c1b0dd648
parent: 1144:bff259181b22
user: user1
date: Fri Nov 13 21:12:21 2009 +0000
summary: Playing with new server view
changeset: 1145:aa06857832ab
user: user1
date: Sat Nov 14 13:54:12 2009 +0000
summary: Updated buttons to something more fitting
changeset: 1144:bff259181b22
user: David Mytton <david@mytton.net>
date: Fri Nov 13 10:35:51 2009 +0000
summary: Example
鉴于这种情况:
a)我在这里导入分支是否有问题?
b)分支机构是否可以实际导入?
答案 0 :(得分:21)
这是设计的。导入的Git分支仅在Mercurial中标记,hg heads
应该为您提供正确数量的导入“分支”。
如this thread中所述:
考虑一个如下所示的树:
o-o-o-o-o-o-b <- branch foo
/
-o-o-a
\
o-o-c <- branch bar
什么分支是“a”及其祖先?
我们没有丝毫的线索。事实上,我们唯一确定的变更集是b nd c,因为分支名称不属于历史记录。
所以:
事实证明,实际上这是不可能的,因为git不能存储足够的信息 考虑一个在git中有两个分支的repo,每个分支都有一些提交 因为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 repo(以防万一,对于男性其他测试)
PS [...]\gitRepoToImport> cd ..
PS C:\Prog\Git\tests\hgimport> git clone .\gitRepoToImport gitRepoToImport1
使用格式~/.hgrc
无BOM 配置您的UTF-8
(花了一些时间才能做到正确!)
[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