Reputation: 23678
I've already tried hg2git through fast-export and I've already tried hg-git.
Both with no success. hg2git actually worked, but I had to ask a friend who runs a Unix machine to do it. And that messed up all the linefeeds throughout the files.
hg-git simply failed with some libzip compression error.
Has anyone had any success converting a hg repo to git on Windows?
To be clear, I don't care about interop. I want to port the whole repo from hg to git, taking the history with me. I don't need to push changes back and forth - only convert once.
Upvotes: 48
Views: 22459
Reputation: 1129
Here are all the pieces put together for a migration on Windows.
Prerequisites
During install, allow binding to .sh files.
Ensure that all tools are available in the PATH environment variable.
Migration
Open cmd.exe
mkdir c:\git_work
cd c:\git_work
git clone http://repo.or.cz/r/fast-export.git
This creates folder: c:\git_work\fast-export\
Now you need mercurial libs for python. Either get them from here or do the following steps.
Edit c:\git_work\fast-export\hg-fast-export.py:
import sys # move this line up here
# Add a new line that imports [mercurial libraries][2] from this zip:
sys.path.append(r'C:\Program Files\TortoiseHg\lib\library.zip')
# ...above the old line:
from mercurial import node
mkdir MyNewGitRepo
Copy content of fast-export to MyNewGitRepo, ignore .git*
hg-fast-import.sh -r c:\Path\To\MyOldHgRepo
If this fails with "Error: repository has at least one unnamed head..." call the last line with parameter: --force
Remove the migration scripts:
git clean -n # see what would happen git clean -f # delete migration files
Restore missing files by resetting the index and working tree.
git reset --hard
Upvotes: 7
Reputation: 8828
Not any more. Dead as a Dodo.
An easy way to convert between Git & Hg with no local process is to open a free KilnHg / Fogbugz account, create a private repo, push one format to it then pull in the other format, it works with both Git & Hg and (should) do seamless conversions.
Upvotes: 2
Reputation: 2004
How to convert a Mercurial repo into a Git repo.
This is one of the most asinine sequences of events I have ever had to figure out, but I am not a Python guy at all.
(If you installed everything you should see it download and compile the Mercurial module)
Upvotes: 14
Reputation: 601
If you happen to be using GitHub and your Mercurial repo is available via HTTP/HTTPS...
In the course of using fast-import (a great tool, that converted my repo without issue) and pushing my new git repo from my dev box to GitHub, I noticed an option to "Import Code from Another Repository" during the "Quick Setup" portion of my git repo on GitHub.
I tested it out and achieved the same results as using fast-import. Using the GitHub import option turned out to be a bit easier in my case than fast-import (again, nothing against that tool, and no, I don't work for GitHub). The steps which worked for me were:
Upvotes: 6
Reputation: 4253
I tried some of the other answers here and didn't have much luck. Here is the pretty straightforward method that what worked for me, after much trial and error:
First, download the hggit extension and add it to your ~/.hgrc or mercurial.ini file if you have not already done so:
[extensions]
hggit=\path\to\hg-git
For each branch you want to bring over to Git, add an Hg bookmark to the tip of the branch:
hg bookmarks hg-default
Then use hggit to create a git repo in the same folder as your current Hg repo by running hg gexport
. A .git folder will have been added as a result. When you then delete the .hg folder from your repo, you will be left with a local git repo.
Upvotes: 2
Reputation: 101
If anyone is using Homebrew on OS X and wants to know the minor tweaks to get it to work properly please see the article here: http://www.ccannon.net/mercurial-to-git-conversion-with-homebrew.html
Upvotes: 0
Reputation: 42374
Did the following on my Mac to successfully export a Mercurial repo to Git (with full branches):
mkdir myrepo; cd myrepo;
git clone git://repo.or.cz/fast-export.git .
rm -rf .git .gitignore
git init
./hg-fast-export.sh -r ../path/to/local/hg/repo
git clean -f # remove fast-export files
Upvotes: 57
Reputation: 879
As of today, git distribution includes a tool to convert mercurial repositories to git, hg-to-git. If you have a recent git version installed, it is there. Worked very well for me.
Upvotes: 7
Reputation: 3768
Here is a simple example of how to export your local clone of a Mercurial repo to GitHub.
First, add the hggit
extension to your ~/.hgrc
file if you have not already done so:
[extensions]
hggit =
Then run the following commands from the root of your Mercurial repository:
hg bookmark -r default master
hg push -f git+ssh://[email protected]/bolinfest/plovr.git
Personally, I had to specify -f
when running hg push
, though I suspect it is because I had some complicated branches in my Mercurial repo. You may not find it necessary for your migration.
Make sure that you have the git+ssh:
URI to your GitHub repo rather than the git:
URI. (The git+ssh:
URI is a bit harder to find in the new GitHub UI.)
Depending on the size of your repo, running hg push
may take awhile, so be patient. When you are done, you should be able to see your project on GitHub. In this example, my project was available at https://github.com/bolinfest/plovr.
As you would expect, now anyone can clone your public GitHub repo as follows:
git clone [email protected]:bolinfest/plovr.git
Upvotes: 9
Reputation: 5129
Have you tried tailor? It can pretty much convert anything to anything, as VCS go, and is even able to do it incrementally (that is, you convert once, then add new commits from the source to the target, without reconverting from scratch). You may not need it now, but it still is a nice feature.
Upvotes: 2
Reputation: 78350
If you're really only looking to do it this once you can use hg export
like this:
hg export 0:tip -o all-changesets-in-one.patch
or if git prefers only one patch per file you can create one per changeset like this:
hg export 0:tip -o changeset-%r.patch
presumably git apply
can take one or the other of those formats.
Upvotes: 4
Reputation: 25255
There doesn't seem to be any reason you can't run hg2git on windows. It's python which has a windows port. Just make sure the proper libraries are there and run it on the window box.
Upvotes: 0