November 29, 2012
Convert SVN Repository to Git with Full History on Windows using svn2git
I’ve already moved to GIT few years ago, but I was still using SVN for many local repositories. Recently I’ve decided to move all local/online source control repos to GIT, and yesterday I had the time to do so.
I’ve searched for the best way to migrate SVN to GIT with full history & found that svn2git is the best solution & recommended by Github, I’ve used it for almost 95% of repos, while the other 5% failed to complete conversion for some reason!! I’ve found another workaround alternative using SubGit & done the rest 5%.
The Recommended Method using svn2git:
- Download msysgit (Git for Windows)
- Download Ruby Installer for Windows (required for svn2git installation)
- Download RubyGems (required for svn2git installation)
- Install msysgit (Git for Windows) -follow installation instructions & you’re done-.
- Install Ruby Installer for Windows -follow installation instructions & you’re done-.
- Install RubyGems
- Extract RubyGems files
- Open CMD & go to the extracted RubyGems folder
- Run this command in CMD “without quotes”: “ruby setup.rb”
- Install svn2git by running this command in CMD “without quotes”: “gem install svn2git”
- You’re ready now to takeover the actual SVN → GIT conversion!
- Now create a new text file & place in it your authors mapping, this file will be used in the conversion process to map old SVN commit authors to your newly desired ones, you can map multiple authors to single author as well if you wish. Make sure to use this syntax (spaces allowed in both sources & destination names) “without quotes”: “Old Source Author = New Destination Author <email@example.com>”
- After saving your authors mapping file, switch to CMD & go to the directory where you need your new GIT repository to be places (anywhere), and run the following command (while ../authormap.txt is the path to your authors mapping file, and -v just to display what’s going on & what’s being processed now, otherwise it will be confusingly silent):
svn2git http://svn/repository/url/ –authors ../authormap.txt -v
The Workaround Method using SubGit:
- Extract SubGit files
- Open CMD & go to SubGit extracted folder, then go to bin
- Now run the following command in CMD (This will configure & prepare the repository):
- subgit configure /path/to/svn/repository
- Make sure to update authors mappings in confauthors.txt found inside the original SVN repository path.
- Now run the following command in CMD (This will do the homework):
- subgit install /path/to/svn/repository
- And finally you can go to the directory where you need your new GIT repository to be places (anywhere) and Clone the SVN repository AS-IT-IS GIT repository by running the following command in CMD:
git clone /path/to/svn/repository
- Always make sure to allow installed tools to add itself to system’s “Path” Environment Variable.
- In case of SubGit method I’ve followed the default instructions in the official manual by using paths not URLs, and since I’ve all my SVN repositories locally I didn’t need to check how to do it using URLs like svn2git, also it’s just a workaround for the svn2git unknown shortage.
- svn2git Official repository on Github
- SubGit Official Website
Done, Congratulations! You’ve two excellent methods to convert SVN repositories to GIT repositories easily & smoothly on windows.