with - svn to git migration script
Convert Mercurial project to Git (6)
Another option is to create a free Kiln account -- kiln round trips between git and hg with 100% metadata retention, so you can use it for a one time convert or use it to access a repository using whichever client you prefer.
This question already has an answer here:
I need to convert a mercurial project to a git project, but I would like to keep the commit history intact. My current solution was to just remove hg related files and then git init && add manually the files I needed, but that would not keep the history. Are there any solutions to this?
It’s a relatively simple process. First we download fast-export (the best way is via its Git repository, which I’ll clone right to the desktop), then we create a new git repository, perform the migration, and check out the HEAD. On the command line, it goes like this:
cd ~/Desktop git clone git://repo.or.cz/fast-export.git git init git_repo cd git_repo ~/Desktop/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo git checkout HEAD
You should see a long listing of commits fly by as your project is migrated after running fast-export. If you see errors, they are likely related to an improperly specified Python path (see the note above and customize for your system).
That’s it, you’re done.
If you want to import your existing mercurial repository into a 'GitHub' repository, you can now simply use GitHub Importer available here [Login required]. No more messing around with fast-export etc. (although its a very good tool)
You will get all your commits, branches and tags intact. One more cool thing is that you can change the author's email-id as well. Check out below screenshots:
Ok I finally worked this out. This is using TortoiseHg on Windows. If you're not using that you can do it on the command line.
- Install TortoiseHg
- Right click an empty space in explorer, and go to the TortoiseHg settings:
Open a command line, enter an empty directory.
git init --bare .git(If you don't use a bare repo you'll get an error like
abort: git remote error: refs/heads/master failed to update
cdto your Mercurial repository.
hg bookmarks hg
hg push c:/path/to/your/git/repo
In the Git directory:
git config --bool core.bare false(Don't ask me why. Something about "work trees". Git is seriously unfriendly. I swear writing the actual code is easier than using Git.)
Hopefully it will work and then you can push from that new git repo to a non-bare one.
This would be better as a comment, sorry I do not have commenting permissions.
@mar10 comment was the missing piece I needed to do this.
Note that '/path/to/old/mercurial_repo' must be a path on the file system (not a URL), so you have to clone the original repository before. – mar10 Dec 27 '13 at 16:30
This comment was in regards to the answer that solved this for me, https://.com/a/10710294/2148757 which is the same answer as the one marked correct here, https://.com/a/16037861/2148757
This moved our hg project to git with the commit history intact.