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

28,624

Solution 1

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]

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

4) Find the line that says

;convert =

and delete the semicolon so it reads

convert =

</Enable Convert Extension Manually>

5) 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).

6) 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

  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

Mercurial has a built-in conversion extension for this.

Solution 4

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

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

Share:
28,624
David Lay
Author by

David Lay

Dot net, Angularjs and Everything Web

Updated on September 19, 2020

Comments

  • David Lay
    David Lay almost 4 years

    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?

  • David Lay
    David Lay about 15 years
    I know, It's the first thing i stumbled upon, but quoting: "Note that you can't do this with the Win32 Mercurial binaries -- there's no way to install the Subversion bindings into its built-in Python library" I'm using TortoiseHg ...
  • Ben Moss
    Ben Moss about 15 years
    Use a Linux live CD or a virtual machine?
  • David Lay
    David Lay about 15 years
    Nopes, neither mercurial binaries for win32 or TortoiseHg comes with convert extensions, so "hg convert" is not even a valid command on win32.
  • van
    van about 15 years
    This is absolutely correct answer. I have done this using hg convert extension only (selenic.com/mercurial/wiki/…) and using the file protocol for SVN repository without pysvn extension: hg convert file:///X:/HOME/REPOS/mysvnrep newhgrep
  • fglez
    fglez about 15 years
    I tried using svn:// instead of file:// but it keeps asking for Python bindings
  • David Lay
    David Lay almost 15 years
    Selecting the answer for this question was difficult. evilbloodydemon was right when he commented in his answer to edit the config to enable the convert extension, but this answer is more clear and precise
  • Yousaf
    Yousaf almost 15 years
    I just wanted to mention that i tested this without the SVN command line client and it worked as well. You don't even need an SVN server functioning to do this, just access to the repository file path.
  • Jonathan Webb
    Jonathan Webb over 14 years
    This worked well for me with Mercurial V1.4.3. A 1-year-old svn repository converted very quickly with the full history intact. Many thanks!
  • Zarigani
    Zarigani about 14 years
    Thanks, especially for the detailed instructions on which config file to edit. For reference, this also works when converting from an svn repo served over svn://
  • Ahmad
    Ahmad over 13 years
    Just to add - the ini file is not created on a default TortoiseHG installation. You need to apply/save some settings first or start with a blank file if you know what you doing.
  • Petter Wigle
    Petter Wigle over 13 years
    Using svn:// instead of file:// worked for me without the Python bindings. To start the svn server the command is: svnserve -r <path to repo root> -d
  • Bart Verkoeijen
    Bart Verkoeijen over 13 years
    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.
  • Tchami
    Tchami over 12 years
    Just a minor suggestion. If you add the debug and traceback options to the convert command in step 6, you will get a lot more details when converting a repository, e.g. "hg convert --debug --traceback file://y:/yoursvnreponame". I was wondering why the converting process seemed to hang at first, but with the debug and traceback options you can actually see what's going on at all times.
  • Ben Page
    Ben Page over 11 years
    Hi, is it possible to explain why you should not init the first repository?
  • ACP
    ACP almost 9 years