2009-11-16 9 views
17

Ho un certo numero di rami in un repository git:Come vengono importati i rami git in mercurial con hg convert?

[email protected] ~/app: git branch -r 
origin/HEAD -> origin/master 
origin/master 
origin/newButtons 
origin/newFonts 
origin/serverView 

Se provo e importare questo git repo in mercuriale:

[email protected] ~/: hg convert app 
... 
[email protected] ~/app-hg: hg update 
388 files updated, 0 files merged, 0 files removed, 0 files unresolved 
[email protected] ~/app-hg: hg branches 
default      1148:6d04af619607 

Sembra che i rami sono stati "persi" (in termini di loro non essere separati) ed effettivamente fuse in punta:

[email protected] ~/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 <[email protected]> 
date:  Fri Nov 13 10:35:51 2009 +0000 
summary:  Example 

Dato che è il caso:

a) Sto facendo qualcosa di sbagliato per importare i rami qui?

b) Le filiali possono essere effettivamente importate?

risposta

21

Questo è di progettazione. I rami Git importati sono etichettati solo in Mercurial e hg heads dovrebbe fornire il numero corretto di "rami" importati.

Come menzionato in this thread:

consideri un albero che assomiglia a questo:

 o-o-o-o-o-o-b <- branch foo 
    /
-o-o-a 
     \ 
     o-o-c <- branch bar 

Cosa ramo sono "una" e suoi antenati su?
Non abbiamo il minimo indizio. In effetti, gli unici changeset di cui abbiamo certezza sono b cn perché i nomi dei rami non fanno parte della storia.

Quindi:

scopre che in realtà è impossibile fare questo diritto, perché Git non memorizza informazioni sufficienti.
Considera un repo con due rami in git, ognuno con un numero di commit.
Poiché git non registra il ramo su cui è stato eseguito il commit, non c'è abbastanza informazione nell'albero per etichettare ciascun changeset.
Un utente git può scambiare i nomi dei due rami e nulla viene registrato per dire che è stato sempre diverso. Se due rami hanno un antenato comune (e quasi certamente lo saranno), su quale ramo è ancestrale? Non lo sappiamo

Il meglio che possiamo fare nel caso generale è etichettare ogni testa di ramo come su quel ramo. Quindi se fai una conversione incrementale, probabilmente faremo la cosa giusta. Ma il concetto di git di rami non è perfetto per hg, quindi anche questa conversione non sarà perfetta.


È possibile verificare con un piccolo repo 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" 

Fai un po 'di modifiche in tre rami separati:

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" 

clonare che Git pronti contro termine (nel caso in cui, per maschi altri test)

PS [...]\gitRepoToImport> cd .. 
PS C:\Prog\Git\tests\hgimport> git clone .\gitRepoToImport gitRepoToImport1 

Configura il tuo ~/.hgrc con un formato UTF-8 senza BOM(mi ci è voluto un po 'per farlo bene!)

[extensions] 
hgext.convert = 

poi fare la conversione

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 

otterrete i tre attesi "rami"

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 
+1

* * Nizza risposta. – quark

+6

Il termine "ramo" è eccessivamente sovraccarico in termini DVCS. Sarebbe bello se avessimo un linguaggio concordato per distinguere facilmente tra i vari significati (per esempio forchette di grafico, teste etichettate, revisioni etichettate). – quark

Problemi correlati