How to migrate/convert from SVN to Mercurial (hg) on windows

SvnVersion ControlMercurialMigrationHgsvn

Svn Problem Overview


I'm looking for a tool to migrate a couple of SVN repositories to Mercurial, with history, labels and so on.

I'm using TortoiseHg (Windows x32), so ConvertExtensions are discarded. There's some info on how to do this process on a Linux box (hgsvn), but I don't have a Linux machine available.

Can I use those Python scripts on Windows? If so, what do I need to do it? Or, what other tools can I use to do this process?

Basically, how can I convert an SVN project to Mercurial?

Svn Solutions


Solution 1 - Svn

I just had to tackle this problem myself. I have a windows XP machine with a separate windows server hosting VisualSVN Server.

I also have TortoiseHG installed as well as the CollabNet Subversion Command-Line Client.

<Enable Convert Extension w/ Tortoise Hg 2>

Many thanks to bgever for pointing out in the comments that with TortoiseHg 2.0, enabling the convert extension is easier than ever. As he says

> With TortoiseHG 2.0 this has been made > much simpler: Start the TortoiseHG > Workbench from the Start menu. Select > File --> Settings. Select Extensions > from the list. Check the 'convert' > checkbox and click OK. That's it! No > need to try to generate the config > file anymore and search it in the file > system. – bgever Mar 11 at 7:56

</Enable Convert Extension w/ Tortoise Hg 2>

<Enable Convert Extension Manually>

To convert a repository from SVN to HG, I followed these steps:

  1. Open C:\Program Files\TortoiseHg\Mercurial.ini

EDIT

FYI - Tortoise Hg has migrated this file to

  • XP or older - C:\Documents and Settings\USERNAME\Mercurial.ini
  • Vista or later - C:\Users\USERNAME\Mercurial.ini

That file will be mostly empty and you'll just list what you'd like to override there. If that's what you have, simple add these two lines to the very end of the file:

[extensions]
convert =

2) Search for the line that begins with

> [extensions]

  1. Below it you'll see a list of keywords, commented out with a semicolon (;) on each line

  2. Find the line that says

> ;convert =

and delete the semicolon so it reads

> convert =

</Enable Convert Extension Manually>

  1. Open the command prompt and navigate to the directory that you'd like the new hg folder created in (the process will create a new folder called yoursvnreponame-hg in the directory that the command prompt is open to).

  2. Use this command

> hg convert file:///y:/yoursvnreponame

I found that the convert tool can have problems with networked repositories, so I had to map a drive to it, but this worked just fine for me.

Solution 2 - Svn

  1. startup svn server on localhost
  2. hg convert svn://localhost/your_repo
  3. done, because svn bindings needed only for file:// protocol

Solution 3 - Svn

Solution 4 - Svn

To convert an SVN Repo to an HG Repo AND copy it to a different server, you will need a few things.

  1. TortoiseHG installed. (Check to see what version is currently being used)
  2. Python Installed. (Check to see what version is currently being used)
  3. The Python Modules (you can find them http://pysvn.tigris.org/project_downloads.html)
  4. You will need to add the convert extension to Tortoise. Start the TortoiseHG Workbench from the Start menu. Select File -> Settings. Select Extensions from the list. Check the convert checkbox and click OK.

First the conversion…

  1. It is best to map the Folder that the current SVN Repo is in to the computer you are working on. (i.e. \\server\folder Do not map the SVN Repo folder itself. Map the folder just above it) Give the mapped drive a letter, like Y:\
  2. Open a command Prompt and type: CD /D Y:\
  3. At the Y:\ prompt type: hg convert y:/RepoName (use the name of the current Repo) Be careful of the forward and back slashes. The one in the command is a forward slash. Also, if the name has spaces, put the name in quotations. (i.e. Y:/"My Repo folder")
  4. Now it should be running and will create another folder alongside the old one. And an hg folder should be inside. IT WILL NOT BE INITIATED, AND DO NOT INITIATE!
  5. The conversion is complete.

Second the cloning…

  1. Open TortoiseHG Workbench. Go to File -> Clone Repository
  2. Source: Enter the full path of the converted repo.
  3. Destination: Enter the full path of where you want the repo cloned. It is not necessary to create a folder at the new destination as the cloning process will create it and initialize it.
  4. Add the permissions to the new cloned folder.
  5. You’re done!!!

Solution 5 - Svn

Nobody still does not mention hgsubversion (Extension Wiki), which can do it without almost any headache (excluding rare cases and specific tree).

Just add extension, enable it and hg clone SVN_REPO to local mercurial repo

Solution 6 - Svn

This is in the TortoiseHg FAQ:

> ### How can I convert a subversion repository to Mercurial? ### > > You must install svn-win32-1.4.6 command line tools, then add them to your path. Then you must enable the convert extension. At this point, you should be able to use the 'hg convert' command to do the conversion. Please direct problems/questions about the convert extension to the Mercurial mailing list or #mercurial on irc.freenode.net.

So it is apparently possible -- I'm using Linux so I haven't tried myself.

Solution 7 - Svn

I just converted a remote SVN repo with HTTP auth to a Mercurial repo, and let me tell you, there's not a lot of documentation on how to do this. I had to download the Mercurial source and install it stand-alone, using the source package, that way the SVN bindings will work the right way.

I installed it like:

python setup.py install

Which worked just fine on my Server 2003 box. I can now convert an SVN repo the correct way, by doing something like this:

python c:\python26\scripts\hg convert <remote repo>

The documentation for ConvertExtension on the Mercurial site isn't terribly clear, but it does say this:

> There's no way to install the > Subversion bindings into [Mercurial's] built-in > Python library. So you'll need to use > a Mercurial installed on top of a > stand-alone Python

So now I just use the stand-alone version for converting, and TortoiseHg for actual VCS work.

Solution 8 - Svn

better late than never ...

Two answers for the price of one ...

  1. If it is a public, open-source repo you could just use http://svn2github.com/add/ which took about half an hour to clone that repo to GitHib and then just pull that into Hg.

  2. The advantage of using hg convert is that is can be resumed. Converting SVN to Hg can take days. If you stop this it will resume from where it left off.

Below is a batch file I wrote because Codeplex SVNbridge rubbish. The repo in this example did take a couple of days to fetch the whole history (I'm in Australia so the latency may have been a factor). I'd like to think it gave a TFS server somewhere a good beating.

This batch file can be run at any time to pull updates from the SVN source if they happen to be the only ones left on earth actually still using SVN. I haven't tested it so see what happens if you do this so if I were you I'd abandon the original branch if you're going to edit the repo.

The robocopy shamap stuff is to maintain the SVN history if you clone the Hg repo, shamap is ephemeral - check the batch file & shamap in (I'd do that on a new branch).

the batch...

@echo off
mode con:cols=100 lines=800

:: Change the SVN remote name here
::
set remote=https://cinch.svn.codeplex.com/svn
::

title Fetching SVN from %remote%. This could take...DAYS
echo .
echo Fetching SVN checkins from %remote%
echo .
echo Dependencies: Tortoise Hg and hg.exe in the Path would be ideal.
echo using hg convert
echo .
echo First, I will make a backup of shamap in the hg repo folder.
echo If shamap in .hg\ is newer then it will be copied to the repo.
echo You should commit it so hg clones of this repo work with this.
echo Commit this .BeeyATch file as well.
echo shamap keeps track of what has been fetched from SVN.
echo ok, that ends the educational part of this script...
echo Now I will fetch SVN changes from
echo %remote%
echo ...
echo ...(this could take quite some time)...
echo ...DAYS...yes...DAYS
echo ...especially if it's fecking Codeplex SVN...
echo .
echo If this craps out just run it again - it will resume from where it left off. 
echo and fetch the rest...eventually
echo .
echo Control C to abort or any other key to start:
echo .

pause

echo .
:: http://mercurial.selenic.com/wiki/ConvertExtension <== see for details of shamap
:: copy the shamap from the original convert into the .hg folder unless it is already there & newer
:: don't panic if shamap is much bigger than the original - diff it to see why
robocopy .\ .\.hg\ shamap /XO 
robocopy .\.hg\ .\ shamap /XO 
echo .

hg convert --verbose --debug %remote% "%CD%"
echo .
echo .
echo Finished fetching from %remote%
title Finished fetching from %remote%
echo Any  key to Exit
echo .
pause

exit

Solution 9 - Svn

Using the convert extension of Mercurial:

  1. Enable convert extention; add convert= to the [extensions] section of .hgrc like this: > [extensions]
    convert=
  2. Linux needs additional python bindings: sudo apt-get install python-subversion
  3. Execute hg convert command
  • See hg convert -h for help
  • Example: hg convert http://[svnserver]/[Project] --source-type svn [DestinationDir] (see note 2)
  1. Push to newly created Mercurial repository: hg push https://[mercurialserver]/[Project]

note: you can even repeat the hg convert command to include new changes made in the svn repository after the previous convert.

note 2: When hg convert doesn't work using http:// or svn:// you could first checkout the Subversion repository (or update an existing one) and convert using the local checkout; example: hg convert [DirectoryOfLocalCheckout] --source-type svn [DestinationDir]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid LayView Question on Stackoverflow
Solution 1 - SvnMichael La VoieView Answer on Stackoverflow
Solution 2 - SvnevilbloodydemonView Answer on Stackoverflow
Solution 3 - SvnChad BirchView Answer on Stackoverflow
Solution 4 - SvnSueSView Answer on Stackoverflow
Solution 5 - SvnLazy BadgerView Answer on Stackoverflow
Solution 6 - SvnMartin GeislerView Answer on Stackoverflow
Solution 7 - SvnAlex FortView Answer on Stackoverflow
Solution 8 - SvnCAD blokeView Answer on Stackoverflow
Solution 9 - SvnR. OosterholtView Answer on Stackoverflow