Using Hg convert to move projects between repositories

As part of a little bit of re-organisation work I undertook today I needed to move a project out of one Visual Studio Solution into it’s own solution. As part of that move I needed to move the code from it’s original Mercurial¬†repository into a new one.

The first job is to create a new Visual Studio solution in which to put the existing project.

  • Create new empty Visual Studio Solution
  • Create a Mercurial repository in the root folder of the solution
  • Copy my standard .hgignore file and nuget-update.bat files in there
  • Commit all files to the new repository
  • Clone the repository to a temporary “work” one, just in case I screwed something up!
The next job is to move the files over in source control
  • Load up a powershell console
  • cd <cloned repo folder>
  • notepad filemap.txt
  • add “include <path of project relative to root repo path of source solution>” – in my case include “ReadThroughProviders”, this is a folder within the solution folder I’m taking the project from
  • make a backup of the filemap.txt file just in case I need to start again (copy filemap.txt ..)
  • hg convert --filemap filemap.txt C:\Dev\SourceSolutionFolder C:\Dev\TargetSolutionFolder.Clone
  • hg merge
  • hg commit
  • hg update
Note: convert is a mercurial extension, it ships with mercurial so all you need to do is enable it by adding the following to your mercurial config files (.hgrc or mercurial.ini) …


Taken from

To finish things off

  • Add project to the new blank solution in Visual Studio
  • run nuget-update.bat to make sure all my dependencies are okay
  • build the solution to make sure all is well
  • hg commit
  • hg push (I also created a new repository on our Kiln server)

… and relax!

One response to “Using Hg convert to move projects between repositories

  1. I used this “technique” again today, but I tried pulling one project over at a time and for whatever reason it didn’t do anything the second time. So, I just started again and put both projects in my filemap.txt

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s