This page discusses the options for converting from Subversion to Mercurial.
If you want to want import a working copy of your code (i.e. no history) from Subversion into Bitbucket, the Bitbucket importer provides a simpler mechanism for doing so. Please see the instructions on Importing Code into your Bitbucket Repository instead.
Option 1: The hgsubversion Extension – Recommended
The hgsubversion extension is a user-contributed extension, not distributed with Mercurial. We recommend this extension. Please refer to the hgsubversion extension guide for download sites and usage instructions.
Option 2: Mercurial's convert extension
This extension is distributed with Mercurial. Refer to the documentation:
hg convertwithout specifying any arguments to read the Mercurial manual.
- Read about the ConvertExtension on the Mercurial Wiki.
Enabling the convert Extension
First of all, you must enable the
convert extension that ships with Mercurial.
~/.hgrc to look like this:
convert command should now be available.
While Subversion is currently used widely in all kinds of software development projects, more and more projects may want to convert to the DVCS paradigm.
For this example, we will be converting Graham Dumpleton's excellent
mod_wsgi module, which is hosted on Google code.
For Subversion specifically, Mercurial is clever enough to recognize the trunk/branches/tags directory structure used ubiquitously. When you supply an URL for the repository, Mercurial will look for a trunk directory and if it exists, it will use it as the base. If it finds branches or tags it will also attempt to name branches and tags from that.
The Subversion URL for
mod_wsgi is http:modwsgi.googlecode.com/svn. Lets begin by downloading the latest revision of the repository.
NB: You may also point Mercurial directly at the remote repository, although this is not as well supported as a local starting point. If you want to do this, you can skip this step.
Now that we have the latest revision of
HEAD), we have a place we can point Mercurial to. Mercurial will automatically pick up the correct settings and download the full history from the central repository.
You're done! If you cd to the newly created
mod_wsgi_hg directory, you will be entering a fully fledged, history-preserved Mercurial repository, consisting of the exact same files as the Subversion repository.
Now would be a good time to upload your repository to Bitbucket, so go ahead and create your repository on the Create Repository page.
The repository is now uploaded to our servers, and ready to use. Go check it out!
If this last step fails you might also need to run the
hg update command before
hg push as shown in the following example:
The output might look different than this example, however the order of commands is the same.