Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Migrating Repository Data from TFS to SVN with History

0.00/5 (No votes)
28 Apr 2015 1  
This article will help to migrate TFS repository data into SVN repository with history

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.

  1. 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.
  2. 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.

  1. 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
  2. cinst git-tf -force
  3. 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/

  4. 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.

  5. Change your command directory to where .git file is present, e.g.: C:/TFSPROJECT/MyProject
  6. Execute the below commands:
    git add  .
    git commit -a -m "initial commit after git-tf clone"
  7. You should be able to see your TFS project in GIT with history.
  8. You can close Window Command.
  9. Launch VisualSVN and create one new repository say MyProject and copy MyProject reposit
  10. 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.

  11. Initialize git-svn: like below:
    git svn init -s --prefix=svn/ https://MyProject_Url(From step 9 above)(Use your svn server address here)
  12. Fetch the initial stuff from svn using command
    git svn fetch

    Copy the above generated hash code and save it somewhere, say HashCode1.

  13. 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.

  14. 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.

  15. Create the graft using command:
    echo <HashCode1> <HashCode2> >> .git/info/grafts
  16. 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
  17. Drop the graft using command:
    rm .git/info/grafts
  18. gitk should still show svn/trunk in the ancestry of master. Linearize your history on top of trunk using command:
    git svn rebase
  19. And now "git svn dcommit -n" should tell you that it is going to commit to trunk using command:
    git svn dcommit
  20. Add the original Git repo as a remote using command:
     git remote add origin C:/TFSPROJECT/MyProject/.git
  21. 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.

  22. 23. Fetch from GIT using command:
    git fetch origin
  23. 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.

  24. 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.

  25. Now push all the commits into the SVN repository using command:
    git svn dcommit

Note

  1. 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).
  2. 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here