prathmesh.kallurkar
prathmesh.kallurkar

Reputation: 5686

Convert git repo to mercurial repo

I was working on a git repository and now I need to convert it to a hg repository for some reason. My original git repository has 41 commits and had a size of 320MB.

I am trying to convert the repository using hg convert git-repo hg-repo. This command starts converting the git repo to hg but hangs (does not stop) midway at version number 18. I checked that the size of the hg repo at this time was 50Mb. I know that the rev no. 18 and size=15M are not that significant but hg convert is not printing any error that I can debug.

Does hg print error at some unknown location? Does the size of repository have an effect on the "hg convert" program?

Upvotes: 3

Views: 794

Answers (1)

Livius
Livius

Reputation: 3388

hg convert hasn't been the easiest tool to use in my experience, but hg-git has always worked flawlessly for me. Since you mention having some troubles with the git repository a while back, you should try a full integrity check:

git fsck-objects --full

(I'm assuming the repository is local, but if not, make a local clone and check it there.)

It shouldn't be necessary, but you can force a garbage collection before proceeding:

git gc

and if you're really paranoid, you can follow that up with another integrity check. Using hg git (make sure you have it installed and enabled in .hgrc), it's very easy to do a local Mercurial clone:

hg clone path/to/git/repo path/to/hg/repo

(This may take some time -- you are going through the revisions one by one and resaving them.)

Now, the hg clone will actually have a hidden copy of the git repo stored internally -- you can see this by running git status from within the cloned directory. This hidden copy won't transferred on pull or push, so if you really want get rid of the git heritage, you can do another clone:

hg clone path/to/hg/repo path/to/new/repo

If at some point you decide you want to go back to git, you can also do that using the hidden git repo from hg-git:

git init path/to/new/git/repo
cd path/to/new/git/repo 
git pull path/to/hg/repo/.hg/git

If you don't still have the hybrid repo hanging around, you can recreate it in place via hg gexport (part of hg-git) or use something like git-hg or the hg/brz-bridge for git. See also Git interoperability with a Mercurial Repository.

Upvotes: 3

Related Questions