Migrate Mercurial hg repository to git keeping the whole history

5 12 2015

Although hg and git share the same idea of versioning files, git provides much more tools to help teams to maintain code, releases and fixes. That’s why I decided to migrate project repository from hg to git. The method I describe preserves the whole hg history, branches and tags.

Migration with fast-export tool

Fast-export is tool that processes each hg commit and migrates it to git. Tool has the python version that you can run on windows, but it didn’t work for me so i used .sh script on linux on VirtualBox. Steps to migrate are:

  1. clone the fast-export git repo
  2. init your target git repo in path of your choice
  3. run the hg-fast-export.sh script and wait until it finished (migrating 4k commits takes around 20 minutes)
  4. start using your new git repo (checkout HEAD, add remote, push)

In other words execute those commands:

git clone git://repo.or.cz/fast-export.git
git init your_git_repo
cd your_git_repo
~/fast-export/hg-fast-export.sh -r /path_to_old_mercurial_repo
git checkout HEAD

Which will be master branch?

As a default behaviour your default mercurial branch will become master in git.

Filenames containing special characters

If you have filenames with special regional characters (like ą, ó, €) make sure to rename them in your hg repo before migration since, depending on your OS, they may migrate to even more strange chars and you may have problems deleting them from your new git repo.

Nested .git repos in your mercurial codebase

If you have commited the whole git repo and versioned it on mercurial you will not be able to push to the remote git repo after migration. It will fail with error that your new git repo already contains nested .git repos:

remote: error: object a9ee490ac00987835de30bdbc851da5e8d45d28b:contains '.git'

You need to clean up any .git folders from your hg before running migration scripts. Fortunately there is a tool to do it: BFG repo cleaner. Download the bfg.jar and issue the command to delete all .git files from hg repo:

java -jar bfg.jar --delete-folders .git --delete-files .git --no-blob-protection my-repo.git

After the migration and solving all problems described above my new git repo works like a charm!

Advertisements




Connect JIRA with Mercurial Repository

3 08 2013

JIRA has free useful plugin to connect with Mercurial repository. After connecting them team members can see commits connected with particular issue. Here is how to install and configure the add-on

1. Download and install it

Download it by JIRA’s Add-on site on your instance (Administration -> Add-ons). Search for ‘Mercurial Plugin for JIRA‘ By ServiceRocket. Install it. Note that it requires generating licence key (it’s free, however you have to register and purchase it in Marketplace on ServiceRocket site).

2. Configure

To configure Add-on you have to follow instructions from here.

3. Troubleshoot

Since configuration is quite simple, it also causes problems that you have to troubleshoot :) In my case the problem was reported earlier and manual cloning the repository helped. My JIRA instance could not access the Mercurial repository. I just followed solution from here. Basically the same is instructed on this site.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!








%d bloggers like this: