Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Data Migration from TFS to SVN via GIT with History

4.38/5 (6 votes)
11 Jan 2016CPOL2 min read 11.8K  
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”
  2. Install “Git-1.9.5-preview20141217”
  3. Install Chocolatey: open an administrativeexe command prompt and paste the text below:
    JavaScript
    @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex 
    ((new-object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1’))" 
    && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
  4. Copy paste into cmd: cinst git-tf -force
  5. Restart Console (USE NORMAL COMMAND PROMPT ONLY IN ADMIN MODE) and point to the location where you want your TFS folder structure:

    For e.g.: cd C:/MYPROJECT/

  6. Then clone the TFS project (your structure will be in C:/MYPROJECT/Training)

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

  7. Commit (cd to where .git file is present, e.g.: C:/MYPROJECT/Training), REM from the root, add and commit any new files
    PowerShell
    git add .
    
    git commit -a -m "initial commit after git-tf clone"
  8. Now you should be able to see all the Repo in Git with history.
  9. (Now create a SVN Server with link using Visual SVN server and add users and permission to it.) Only for installation SVN server.
  10. 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
  11. Initialize git-svn:
    git svn init -s -prefix=svn/ <a href="https://svn/svn/SANDBOX/warren/test2">https://svn/svn/SANDBOX/warren/test2</a>

    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.

  12. Fetch the initial stuff from svn:
    git svn fetch

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

  13. Now look up the hash of your root commit (should show a single commit):
    git rev-list -parents remote/master | grep '^.\{40\}$'
  14. Then get the hash of the empty trunk commit:
    git rev-parse svn/trunk
  15. Create the graft:
    echo <root-commit-hash> <svn-trunk-commit-hash> >> .git/info/grafts
  16. 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
  17. Drop the graft:
    rm .git/info/grafts
  18. gitk should still show svn/trunk in the ancestry of master. Linearize your history on top of trunk:
    git svn rebase
  19. And now “git svn dcommit -n” should tell you that it is going to commit to trunk.
    git svn dcommit
  20. Now go to the location where the Repository created from the server is and GIT BASH there.
  21. cd project
  22. Add the original Git repo as a remote:
    git remote add origin C:/GIT/OPP/.git
  23. In case the above step went incorrect, you need to remove the origin, by:
    Git remote remove origin

    And then repeat step number 22.

  24. Fetch from it: git fetch origin
  25. 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.

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

  27. 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).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)