Learn-a-holic Geek Notes

Human compiled Brainwork by Kornelije Sajler.

Converting Mercurial (Hg) to Git Repository on Mac

I had to convert the Mercurial (hg) repository to Git repository, and by lot of advises on the Internet, I’ve decided to use Fast Export.

Clone Fast Export

1
$ git clone git://repo.or.cz/fast-export.git

Create a new repository

1
2
3
$ mkdir git_repo
$ cd git_repo
$ git init .

Problems running Fast Export

Getting to know Python with the Mercurial

By running Fast Export I got error message:

1
'ImportError: No module named mercurial'

Essentially this means that Python does not know about Mercurial. The fix for that would be to install Mercurial as a Python module. I’ve used easy_install:

1
$ sudo easy_install -U mercurial

Using “force” option

The next error was:

1
'Error: repository has at least one unnamed head...'

To fix it there was need to set Fast Export with parameter --force.

Starting Fast Export

Make sure you are in the Git repository that you want to convert to:

1
$ cd git_repo

Run from it a Fast Export like this:

Note:

Assumes that the Fast Export in directory up and the hg_repo is the Mercurial repository directory from where you want to convert from!

1
$ ./../fast-export/hg-fast-export.sh -r ../hg_repo --force

After few moments, your Mercurial (hg) repository will be converted to Git one!

And aftrer the conversion is applied run the checkout:

1
$ git checkout HEAD

Beware if you have a lots of branches, that pushing master will only push master. To push evrything to the remote use:

1
$ git push --all origin

And now all commits and previous branches are converted to Git!

Comments