1. 先下載fast-export工具,網頁位置為http://repo.or.cz/w/fast-export.git,可以下載最後的snapshot壓縮檔(http://repo.or.cz/w/fast-export.git/snapshot/aaccfba9a0cfcfdd4db1e629b50d65b1c479b64f.zip),解開後放在一個資料夾中。

2. 進入Mercurial repo中,檢查目前的狀態,如果有未commit的檔案要先處理好。

3. 因為fast-export是sh檔案,所以這邊使用cygwin x86-64 V1.7.25環境。執行範例如下:

$ cd /cygdrive/d/temp/
$ mkdir HGRepoA
$ cd HGRepoA
$ git init
$ ./cygdrive/d/temp/fast-export/hg-fast-export.sh -r /cygdrive/d/temp/HGTools
$ git reset HEAD
$ git co .
$ mkdir HGTools
$ git mv *.* HGTools
$ git commit -am"export Mercurial to Git repository."

意思就是建立一個新的資料夾,並新建立一個Git repo,然後執行fast-export轉換Mercurial變成Git,最後將檔案checkout到目前的目錄中,接著移動到準備要放的目錄,最後就是commit這些變動。
git co就是git checkout,cygwin內建的Git版本應該是1.7.9,沒有設定alias應該是不能這樣用,可以自行設定或者使用Git bash (msysgit)。

4. 由於這次的目的是要將分散很多的Mercurial repositoies合併程單一個Git repository,因為用fast-export轉換的repo好像不能把幾個HG repo合併在一起,所以要把各個HG repo一個一個轉換成Git repo。就是不斷重複進行第三點的步驟。

5. 接下來要進行Git repo合併,這邊使用remote repo-pull合併的方式,範例如下:

$ git remote add MyRepoA ../HGRepoA
$ git pull MyRepoA master

$ git remote add MyRepoB ../HGRepoB
$ git pull MyRepoB master

要注意的是,每個repo裡面的目錄名程不能重複,否則會有蓋檔的問題。

6. 最後合併完成,再push到server。
$ git remote add origin http://192.168.1.100:8080/git/UtilsRepo
$ git push origin master

7. 合併多個Git repo可以用submodule, subtree進行,但這邊考量用remote-pull到同一個地方是比較簡單。

 

後記: MSysgit在push到SCMManager的時候,一直會出現各種錯誤,像是

fatal: could not read Password for 'http://scmadmin@192.168.1.100:8080': No such file or directory

最後還是用cygwin完成push,原因不可考@@。

arrow
arrow
    全站熱搜

    bagatelles 發表在 痞客邦 留言(0) 人氣()