Introduction
Generally, we can find multiple articles over migrating repository from SVN to TFS and but I am listing some steps which will help to migrate data from TFS to SVN with history.
Prerequisites
Before going to start TFS to SVN migration task, there are some prerequisites in terms of software installation on your local/server system.
- Install “VisualSVN-Server-3.2.2-x64”. Download link is https://www.visualsvn.com/server/download/.
After installing VisualSVN, create one admin user and group. - Install “Git-1.9.5-preview20141217”. Download link is https://github.com/msysgit/msysgit/releases/.
Once we install the above two softwares, kindly restart your system.
Let's Get Started
Now follow the below steps one after another.
- Install Chocolatey: open a cmd.exe command prompt in admin mode and paste the text below:
@powershell -NoProfile -ExecutionPolicy unrestricted
-Command "iex ((new-object net.webclient).DownloadString
('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
- cinst git-tf -force
- Restart your console (USE NORMAL COMMAND PROMPT ONLY IN ADMIN MODE) and point to the directory where you want to pull your TFS project.
For example: cd C:/TFSPROJECT/
- Then clone the TFS project using command:
git-tf clone http://TFS_ServerName:PortNumber/tfs/$TFS_Project/MyProject --deep
The above highlighted URL should be your TFS project URL, which needs to be migrated into SVN.
- Change your command directory to where .git file is present, e.g.: C:/TFSPROJECT/MyProject
- Execute the below commands:
git add .
git commit -a -m "initial commit after git-tf clone"
- You should be able to see your TFS project in GIT with history.
- You can close Window Command.
- Launch VisualSVN and create one new repository say MyProject and copy MyProject reposit
- Go inside MyProject folder under Repositories (Default folder created by VisualSVN) and do a right click -> Git Bash Here
This will launch GIT Command prompt window.
Now all the below command operations will happen over GitBash console window only.
- Initialize git-svn: like below:
git svn init -s --prefix=svn/ https://MyProject_Url(From step 9 above)(Use your svn server address here)
- Fetch the initial stuff from svn using command
git svn fetch
Copy the above generated hash code and save it somewhere, say HashCode1
.
- Now look up the hash of your root commit using command:
git rev-list --parents remote/master | grep '^.\{40\}$'
Ignore if any error msg comes after this step.
- Then, get the hash of the empty trunk commit using command:
git rev-parse svn/trunk
Copy the above generated hash code and save it somewhere, say HashCode2
.
- Create the graft using command:
echo <HashCode1> <HashCode2> >> .git/info/grafts
- GIT should show svn/trunk as the first commit on which your master branch is based. Make the graft permanent:
git filter-branch -- ^svn/trunk --all
- Drop the graft using command:
rm .git/info/grafts
- gitk should still show svn/trunk in the ancestry of master. Linearize your history on top of trunk using command:
git svn rebase
- And now "git svn dcommit -n" should tell you that it is going to commit to trunk using command:
git svn dcommit
- Add the original Git repo as a remote using command:
git remote add origin C:/TFSPROJECT/MyProject/.git
- In case of any error in step 20, you need to remove the origin, by:
Git remote remove origin
And then repeat step number 20.
- 23. Fetch from GIT using command:
git fetch origin
- Create a local branch for the remote master using command:
git checkout -b old_master origin/master
Note that master branch is already present, so we define another one.
- Being on
old_master
, we rebase this branch onto master using command:
git rebase --onto master --root
Doing this, we have "moved" all our commits from old_master
to master
.
- Now push all the commits into the SVN repository using command:
git svn dcommit
Note
- Please note that some steps like 22 to 25 may take a little longer time (depending on the size of the repository which you are planning to convert. Ideally for 1 GB, it takes 12 hours on normal system).
- Steps 13 to 19 are not important. You can skip these steps. The importance of these steps comes when we face an error or find a record broken while fetching record into SVN during steps 11 and 12.