如何通过hg convert将git分支导入mercurial? [英] How are git branches imported into mercurial with hg convert?
问题描述
david @ Panama〜/ app:git branch -r
origin / HEAD - >原产地/主产地
原产地/主产地
产地/新产品按钮
产地/新产品种类
产地/服务器产品
如果我尝试将这个git repo导入到mercurial中:
david @ Panama〜/ :hg convert app
david @ Panama〜/ app-hg:hg update
更新了388个文件,合并了0个文件,删除了0个文件,解析了0个文件
david @Panama〜/ app-hg:hg branches
default 1148:6d04af619607
这些分支已经迷失了(不再被分开),而且确实合并为小费:
david @巴拿马〜/ app-hg:hg log
changeset:1148:6d04af619607
标签:tip
用户:convert-repo
日期:Mon Nov 16 17:57:06 2009 + 0000
总结:更新标签
变更集:1147:742e7a01a6c9
父母:1144:bff259181b22
用户:user1
日期:Sat Nov 14 17:47 :09 2009 +0000
总结:玩弄字体以获得更清晰的外观
changeset:1146:162c1b0dd648
父:1144:bff259181b22
用户:user1
日期:星期五11月13日21: 12:21 2009 +0000
总结:玩新的服务器视图
changeset:1145:aa06857832ab
user:user1
date:Sat Nov 14 13:54: 12 2009+0000
总结:更新的按钮更贴合
changeset:1144:bff259181b22
用户:David Mytton< david@mytton.net>
日期:星期五11月13日10:35:51 2009 +0000
汇总:示例
a)我在这里导入分支时做错了什么?
b)实际上可以导入分支吗?
这是设计。导入的Git分支仅在Mercurial中标记,并且 hg标题
应该为您提供正确数量的导入分支。
<正如此主题所述:
考虑一个如下所示的树:
oooooob< - branch foo
/
-ooa
\
ooc < - 分支栏
a及其祖先的分支是什么?
我们没有丝毫的线索。事实上,我们可以肯定的唯一变更是bndc,因为分支名称不属于历史。
原来这样做确实是不可能的,因为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的第一个内容,将在三个不同的分支中演变
在三个单独的分支中进行修改:
PS [...] \ gitRepoToImport> git checkout -b br1
PS [...] \ gitRepoToImport> echo firstEvolutionInBr1>> .\br1.txt
PS [...] \ gitRepoToImport> git commit -a -m分支1中的第一次进化
PS [...] \ gitRepoToImport> echo secondEvolutionInBr1>> .\br1.txt
PS [...] \ gitRepoToImport> git commit -a -m分支1中的第二次进化
PS [...] \ gitRepoToImport> git checkout master
PS [...] \ gitRepoToImport> git checkout -b br2
PS [...] \ gitRepoToImport> echo firstEvolutionInBr1>> .\br2.txt
PS [...] \ gitRepoToImport> git commit -a -m分支2中的第一次进化
PS [...] \ gitRepoToImport> git checkout master
PS [...] \ gitRepoToImport> git checkout -b br3
PS [...] \ gitRepoToImport> echo firstEvolutionInBr3>> .\br3.txt
PS [...] \ gitRepoToImport> git commit -a -m分支3中的第一次进化
PS [...] \ gitRepoToImport> echo secondEvolutionInBr3>> .\br3.txt
PS [...] \ gitRepoToImport> git commit -a -m分支3中的第二次进化
PS [...] \ gitRepoToImport> echo thirdEvolutionInBr3>> .\br3.txt
PS [...] \ gitRepoToImport> git commit -a -m分支3中的第三次进化
PS [...] \ gitRepoToImport> git checkout br2
PS [...] \ gitRepoToImport> echo secondEvolutionInBr2>> .\br2.txt
PS [...] \ gitRepoToImport> git commit -a -m分支2中的第二次进化
PS [...] \ gitRepoToImport> git checkout br1
PS [...] \ gitRepoToImport> echo thirdEvolutionInBr3>> .\br1.txt
PS [...] \ gitRepoToImport> git commit -a -m分支1中的第三次进化
PS [...] \ gitRepoToImport> git checkout br2
PS [...] \ gitRepoToImport> echo thirdEvolutionInBr3>> .\br2.txt
PS [...] \ gitRepoToImport> git commit -a -m分支2中的第三次进化
然后克隆Git回购情况下,男性其他测试)
PS [...] \ gitRepoToImport> cd ..
PS C:\Prog\Git\tests\hgimport> git clone .\gitRepoToImport gitRepoToImport1
配置您的
〜/ .hgrc
格式为UTF-8
不含BOM (花了我一段时间才弄清楚)![扩展]
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
标签:tip
用户:VonC
日期:Mon Nov 16 21:45:35 2009 +0100
总结:第三个分支的演变2
变更集:6:854bc6537c7c
用户:VonC
日期:Mon Nov 16 21:45:19 2009 +0100
总结:分行第三次进化1
变更集:3:9194cf25d3ca
用户:VonC
日期:Mon Nov 16 21:44:09 2009 +0100
总结:分支3中的第三次进化
I have a number of branches in a git repository:
david@Panama ~/app: git branch -r origin/HEAD -> origin/master origin/master origin/newButtons origin/newFonts origin/serverView
If I try and import this git repo into 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
It seems that the branches have been "lost" (in terms of them no longer being separated) and indeed merged into the tip:
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
Given that being the case:
a) Am I doing something wrong to import the branches here?
b) Can the branches actually be imported?
解决方案This is by design. Imported Git branches are only labeled in Mercurial, and
hg heads
should give you the correct number of imported "branches".As mentioned in this thread:
Consider a tree that looks like this:
o-o-o-o-o-o-b <- branch foo / -o-o-a \ o-o-c <- branch bar
What branch are "a" and its ancestors on?
We haven't the slightest clue. In fact, the only changesets we have any certainty about are b nd c because branch names aren't part of history.So:
Turns out it's actually impossible to do this right, because git doesn't store enough information.
Consider a repo with two branches in git, each with a number of commits.
Because git doesn't record which branch each commit originated on, there isn't enough information in the tree to label each changeset.
A git user can swap the names of the two branches and nothing is recorded to say it was ever different. If two branches have a common ancestor (and they almost certainly will), what branch is that ancestor on? We don't know.The best we can do in the general case is to label each branch head as being on that branch. Then if you do an incremental conversion, we'll probably do the right thing. But git's concept of branches aren't a perfect match to hg's so this conversion won't be perfect either.
You can test it with a small Git repo (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"
Make a bunch of modifications in three separate 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"
Then clone that Git repo (just in case, to male other tests)
PS [...]\gitRepoToImport> cd .. PS C:\Prog\Git\tests\hgimport> git clone .\gitRepoToImport gitRepoToImport1
Configure your
~/.hgrc
with a formatUTF-8
without BOM (took me a while to get it right!)[extensions] hgext.convert =
Then make the conversion
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
You will get the three expected "branches"
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
这篇关于如何通过hg convert将git分支导入mercurial?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!