Data migration from TFS to SVN via GIT with history

If you are migrating from TFS (Microsoft) to SVN (Open source) and you want the data with history , you have an option to use GIT and then migrate it .

Below is the procedure of the same :

TFS to SVN with History

  1. Install “VisualSVN-Server-3.2.2-x64”
  1. Install “Git-1.9.5-preview20141217”
  1. Install Chocolatey : open an administrativeexe command prompt 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

  1. Copy paste into cmd : cinst git-tf -force
  1. Restart Console (USE NORMAL COMMAND PROMPT ONLY IN ADMIN MODE) and point to the location where you want your TFS folder structure

                For eg : cd C:/MYPROJECT/

  1. Then Clone the TFS project , (your structure will be in C:/MYPROJECT/Training)

         git-tf clone http://yourtfsservername:8080/tfs/xyz  $/ABC –deep

  1. Commit (cd to where .git file is present eg : C:/MYPROJECT/Training) , REM from the root, add and commit any new files

         git add .

         git commit -a -m “initial commit after git-tf clone”

  1. Now you should be able to see all the Repo in Git with history.
  1. (Now create a SVN Server with link using Visual SVN server and add users and permission to it.) Only for installation SVN server
  1. After step 10, you need to parse to the Repository which has been created by the SVN server and do a right click -> GIT BASH to get GIT Command prompt
  1. Initialize git-svn:

         git svn init -s –prefix=svn/ https://svn/svn/SANDBOX/warren/test2

The –prefix gives you remote tracking branches like “svn/trunk” which is nice because you don’t get ambiguous    names if you call your local branch just “trunk” then. And -s is a shortcut for the standard trunk/tags/branches layout.

  1. Fetch the initial stuff from svn:

git svn fetch

             Steps 13-20 only if there is some problem while performing step no 27.

  1. Now look up the hash of your root commit (should show a single commit):

git rev-list –parents remote/master | grep ‘^.\{40\}$’

  1. Then get the hash of the empty trunk commit:

git rev-parse svn/trunk

  1. Create the graft:

echo <root-commit-hash> <svn-trunk-commit-hash> >> .git/info/grafts

  1. Now, “gitk” 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

  1. Drop the graft:

rm .git/info/grafts

  1. gitk should still show svn/trunk in the ancestry of master.Linearize your history on top of trunk:

git svn rebase

  1. And now “git svn dcommit -n” should tell you that it is going to commit to trunk.

git svn dcommit

  1. Now go to the location where the Repository created from the server is and GIT BASH there.
  1. cd project
  1. add the original Git repo as a remote:

git remote add origin C:/GIT/OPP/.git

  1. Incase the above step went incorrect you need to remove the origin, by

Git remote remove origin

And then repeat step number 22

  1. fetch from it: git fetch origin
  1. create a local branch for the remote master:

         git checkout -b old_master origin/master

Note that master branch is already present, so we define another one.

  1. being on old_master we rebase this branch onto master:

git rebase –onto master –root

Doing this, we have “moved” all our commits from old_master to master

  1. and push all the commits into the SVN repo:

    git svn dcommit

 

Please note some steps like 23,26, 27 may take a long while (depending on the size of the repository which you are planning to convert. Ideally for 1 GB it takes 12 hours).

Leave a comment