hg-fast-export: convert Mercurial repositories to git repositories

There are *-to-git conversion tools for converting almost every SCM repository to a git repository.

I used hg quite extensively earlier this year, but switched to git within the last couple months.  This is partly because I’ve found that git is much faster (on linux) and because it’s easier for me to wrap my mind around the the git philosophy of branching vs. hg’s.  I had to dig up an old mercurial repository from an old project today and was decided to convert it to git.

Here’s what I had to do:

$ git clone git://repo.or.cz/fast-export.git
$ mkdir new_git_repo
$ cd new_git_repo
$ git init
$ /path/to/hg-fast-export.sh -r /path/to/hg_repo
$ git checkout HEAD

A couple notes:

  1. I had to run hg-fast-export.sh instead of hg-fast-import.sh, contrary to what the README said.  Typo?
  2. It doesn’t check out a working copy for you (it’s a feature, not a bug :) ), so I had to do it myself in the last step.
  3. I found that hg-fast-export works better than hg-to-git.  I had some problems converting very large hg repositories.  Maybe it’s preformance-related as hg-fast-export uses the Mercurial and git python libs directly while hg-to-git uses some combination of shell and python.

About these ads

October 16, 2008. Tags: , . Uncategorized.

6 Comments

  1. Tim replied:

    Thanks for posting this, I’m converting a few repositories to Git for the exact same reasons that you described. hg-fast-export is very fast and works really well.

    Git’s ease of branching is what finally pushed me to get used to using it. Mercurial kind of loses me in the way that they do it.

  2. » Convert mercurial repos to git petersteinberger.com replied:

    [...] that from here and the ImportError-fix from [...]

  3. Exporting a hg repository to Git. Or importing into Git a Mercurial repo. « An Unbiased View of The World replied:

    [...] The reason for the title is that it took way longer than it should have to find the solution because I was searching for “importing” not “exporting”. I’m essentially re-posting this blog post, because it was helpful and at the same time hard to find. So here is the credit: http://hedonismbot.wordpress.com/2008/10/16/hg-fast-export-convert-mercurial-… [...]

  4. git vs. mercurial « Rustic Reverie replied:

    [...] now decided to convert my personal repositories to git. This blog post shows how [...]

  5. icy replied:

    Thank you for the post. Converting with the tool is really fast :)

  6. Robin replied:

    Great post, very useful! Made the conversion simple and painless.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback URI

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: