Click here to Skip to main content
15,881,803 members
Articles / All Topics

Data Migration from TFS to SVN via GIT with History

Rate me:
Please Sign up or sign in to vote.
4.38/5 (6 votes)
10 Jan 2016CPOL2 min read 11.3K   4   3
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)


Written By
Software Developer (Senior)
India India
Passionate about Microsoft Technologies like WPF, Windows Azure, ASP.NET, Win Phone and also on Cross platform Mobile Apps, Mongo DB's, IOT & WOT. I love learning and working with (or) Creating Design Patterns . Writer | Technology Evangelist | Technology Lover | Microsoft Developer Guidance Advisory Council Member | Cisco Champion | Speaker |

Blog : http://adityaswami89.wordpress.com/

Comments and Discussions

 
QuestionWrong directory? Pin
pichocki20-Jul-21 23:19
pichocki20-Jul-21 23:19 
QuestionWhy one would want to use SVN? Pin
Philippe Mori11-Jan-16 6:10
Philippe Mori11-Jan-16 6:10 
I was thinking that Git was superior to SVN...
Philippe Mori

AnswerRe: Why one would want to use SVN? Pin
adityaswami8911-Jan-16 15:05
professionaladityaswami8911-Jan-16 15:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.