Fortunately or unfortunately, Git won over Mercurial. I placed a few bets on Mercurial at the time, so I have a bit of a tail of repositories left to convert.
Converting on Windows with full fidelity isn’t really possible. None of the scripts work well, and the case insensitive file system can cause issues. Luckily, Windows Azure makes it super easy to borrow a small Linux instance quickly.
I’ve documented what I do in this post. Anybody with a web browser can follow these steps, on any platform. There looks like a lot of steps, but that’s just because I’m spelling out every last detail for clarity.
Create a Linux VM in Windows Azure
- Sign in to https://manage.windowsazure.com
- Create a new VM from the gallery:
- Choose an Ubuntu release. As of this post, I chose Ubuntu Server 13.10.
- Name the VM anything you want
- Untick “Upload compatible SSH key for authentication”, unless you know what you’re doing there
- Tick “Provide a password”
- Leave all the rest of the defaults, and just keep clicking Next
- Wait a moment for the VM to get provisioned
Connect to the VM
For this, we’ll just be connecting to a command line via SSH: no GUIs will be harmed.
Because SSH is so prevalent, there are tool chains available for every platform. I’m actually writing this post on my Surface RT (not Pro), using an app called SSH-RT from the Windows Store.
- Connect to the DNS name for your new VM (mine was
- Use the username and password you established during the wizard
- You should now be at a command line like
Install Git and Hg on the VM
Ubuntu doesn’t ship with Git or Mercurial installed by default, but it does have an awesome package manager called apt-get.
sudo apt-get install git
sudo apt-get install mercurial
sudo prefix is a command to elevate your permissions, kind of like a UAC prompt on Windows.
hg-fast-export on to the VM
We’ll be using a tool called
hg-fast-export to convert the Mercurial repository to Git, without having to replay each individual changeset like some tools do. This tool is in a Git repo, so we’ll just clone that repository down in order to get it onto the VM.
git clone https://github.com/frej/fast-export.git
Clone your Mercurial repository on to the VM
For the sake of simplicity, we’re just going to use HTTPS instead of SSH.
hg clone https://your/hg/repo/address
Export your Mercurial repository to a new Git one
- Create a new folder for your Git repository:
- Change to that folder:
- Initialize an empty Git repository there:
- Do the fast export:
../fast-export/hg-fast-export.sh -r ../your-repo/
Upload your Git repository to your Git hosting
- Add the remote:
git remote add origin https://your/git/repo/address
- Push up all branches and tags:
git push -u origin --all
Convert Hg-specifc config to Git
Take the opportunity now to convert your
.hgignore file to an equivalent
.gitignore one. You can go and do this back on your own machine.
Delete the VM
Back in the Azure Management Console, delete the VM. When you do this, choose to “delete the attached disks”. (It will ask you.)
You’re all done. Wasn’t that just a perfect, easy use of the cloud?