Converting Mercurial To Git
Today I wanted to convert a Mercurial repository I was using to the git format so that I can put it onto Github. Previously I had used Tailor to perform a migration of a different repository from Monotone to Mercurial. When I tried this with git on OSX 10.5 however, I ran into a path issue with the git command. Whilst trying to debug this, I stumbled across the hg-to-git tool written by Stelian Pop, who wrote this tool for better branch handling. Because it saved me a lot of time that I would have spent trying to debug tailor, I've decided to make a record of how to use the converter for future reference.
First of all you need to get the tool from the git repository:
$ git clone git://repo.or.cz/fast-export.git
After that, create a new directory to house the new git repository, initialize a new git database and then point the export tool at the location of your hg repository:
$ mkdir TARGET_REPO
$ cd TARGET_REPO
$ git init-db
$ ../fast-export/hg-fast-export.sh -r PATH_TO_HG_REPO
master: Exporting full revision 1/19 with 14/0/0 \
added/changed/removed files
.....
Exporting tag [0.1] at [hg r8] [git :9]
.....
Issued 23 commands
git-fast-import statistics:
.....
Then you can push the new repository out to wherever you remote repository is located:
$ git remote add origin git@github.com:0x6e6562/as3-amqp.git
$ git push origin master
Counting objects: 293, done.
Compressing objects: 100% (79/79), done.
Writing objects: 100% (293/293), 1.70 MiB, done.
Total 293 (delta 157), reused 293 (delta 157)
To git@github.com:0x6e6562/as3-amqp.git
* [new branch] master -> master
And now the code is on Github in this project.

Reader Comments