Migrate an existing repository from Subversion to Git on Windows with history intact
To continue my quest of converting from CVCS's to git, I figured I would do a short write up on my recent experience with converting from Subversion in a Windows environment. The experience has been quite similar to my TFS conversion, though there is a bit more setup involved. With that said, the process starts with a great open source tool called svn2git. The tool aims to preserve all commit history, tags, and branches in a way that is meaningful in git. In my experience thus far, it does that job very well. So lets get started!
Step 1 - Install
Install Ruby for windows
choco install ruby
No Chocolatey? Head over to http://rubyinstaller.org/ to grab the installer for a manual install. Make sure to check "add ruby executables to your PATH".
Step 1.5 - Patch Ruby gems
Ruby gems is broken on on Windows since 2.4.x was released, so we need to address that first to make the install process and future gem installs easier. Follow the instructions here https://gist.github.com/luislavena/f064211759ee0f806c88 to get things resolved. There is also a nice explanation there of the actual issue to give you some context.
Step 2 - Install svn2git
Now that the ruby package manager is fixed, installation is simple
gem install svn2git
Step 3 - Initiate Conversion
If you are using the default subversion layout, then the following command will kick things off: (http:// or svn://)
For any non standard repository structures or for a full list of args, the svn2git readme has you covered.
Unlike converting from TFS to Git, commit author information when translating from SVN to Git does not map as easily. For the best possible results, you'll want to create an Author mapping file which will tell svn2git how to map each user in Git. It's a simple text file that you'll pass in with your conversion command. Each line in the file connects an svn username
firstLastInitial to a git username/email
first last <email@example.com>.
svn2git http://svn.example.com/path/to/repo --authors ~/svn2gitAuthors.txt
Step 4 - Prep & Cleanup
Now that you have a git version of your subversion repository, you'll want to clean up some files and add some others to make things a bit more git friendly.
If this is a Visual Studio solution, you may need to remove the Subversion source control bindings. Simply make small edit to your .sln files removing a section that resembles GlobalSection(SubversionScc) ... EndGlobalSection in your favorite text editor.
Add a .gitignore file. It's likely your project or solution will have some files you won't want in your repository (packages, obj, etc) once your project is built. If this is a Visual Studio project, a near complete way to start is by copying everything from the standard VisualStudio.gitignore. For any other project or stack these templates will get you started. This will ensure all of the build generated files, packages, test results, etc will not be tracked in your new repo.
Add a .gitattributes file to help git understand how to deal with project or stack specific files. e.g. How should a .csproj file be treated? Here is a good collection of templates to get you started with yours https://github.com/Danimoth/gitattributes. You'll also find a similar attributes file created for you if you've ever initialized a git repo using the GitHub client for Windows.
Add an optional README.md file (markdown or text). A standard GitHub convention that I've become accustomed to, even for private repositories. Great way to quickly outline things about your project that would be useful at a glance, such as build instructions, usage docs, or any other useful info.
Step 5 - Commit & Push
Now that I've git-ified the repository, it's time to commit the files, add the remote, and push the new branch out to your favorite hosted git repository. I recommend Github, but to save on cash, both Bitbucket or Gitlab are also excellent choices for private repo's.
Credit to Troy Hunt who's writeup helped me as well http://www.troyhunt.com/2014/08/migrating-from-subversion-to-git-with.html