Skip to content

Steve Hill

Versioning: Lossless Conversion from Hg to Git

git, mercurial1 min read

I recently migrated from a private repository on Bitbucket to a public repository on Github. I didn't want to lose my 168-commit history with the move, so naturally I started searching for ways to export my Mercurial history.

The ironically named Semi-useless rhetoric blog was one of the first hits.

The blog's advice:

1$ git clone git://
2$ mkdir new_git_repo
3$ cd new_git_repo
4$ git init
5$ /path/to/ -r /path/to/hg_repo
6$ git checkout HEAD`

I ran into trouble with the hg-fast-export line. My terminal issued the following:

1File "/DIRECTORY_I_CLONED_TO/fast-export/", line 6, in from mercurial import repo,hg,cmdutil,util,ui,revlog,nodeImportError: No module named mercurial

That was nonsense. I suspected I had multiple versions of python installed. Good news! The python_select tool makes it easy to choose a default installation of python. So let's install it:

1$ sudo port install python_select
2$ sudo python_select -s`
3 --> python26-apple*
4$ sudo python_select -l`
5 --> current none python26 python26-apple*
6$ sudo python_select python26`

We can verify this version of Python actually has our module in it

1$ python
2>>> help('modules')

Now we're all set for hg-fast-export.

Note My system is Mac OS X 10.6 with Mercurial installed from MacPorts.