April 14, 2014

Migrate from SVN to TFS (or git)

This time the post wll be not directly about Sitecore but for a task I had for a sitecore project: migrate from SVN to TFS

You have of course some tools who allow you to do that but most of the time you need to pay for it and in fact it is really simple to do that in command line.

In TFS 2013, you have two option for the source control:

  • GIT
  • TFS

So I will explain both by using a powershell script. To do that, you just need to create a file with the ps1 extension and then execute it from a powershell command window. If you have the warning who say that the file must be signed you need to execute the following command first:

Set-ExecutionPolicy Unrestricted

  • For both scenarios you will need to migrate first from SVN to a local git repository. So the first thing to do (if not yet done) is install git: http://git-scm.com/downloads
  • For the second step, you need to migrate from svn to your local git by doing the following code:
    $svnPathToMigrate = "http://svn.lbigroup.be:6060/svn/my-project/trunk"
    
    $targetGitPath = "c:\Projects\Tests\GitOfMyProject"
     
    #Create the folder for the local git 
    md $targetGitPath
    #Browse into this folder
    cd $targetGitPath
    
    #Create the empty git repository
    git svn init $svnPathToMigrate --no-metadata
    #Get the sources from svn into the git repository
    git svn fetch
    
  • Depending of the source control system
    • For Git:
      $tfsGitTarget = "http://betfs01:8080/tfs/MyProjectCollection/_git/MyProject"
      #Synch the local git with the TFS collection
      git remote add TfsGit $tfsGitTarget
      git push TfsGit master
      
    • For TFS:
      • You first need to install git tf
      • $tfsTargetCollection = "http://betfs01:8080/tfs/MyProjectCollection"
        $tfsTargetProject = "$/MyProject"
        #Push to TFS
        git tf configure $tfsTargetCollection $tfsTargetProject
        Git tf checkin --deep --no-lock
        

1 comment:

  1. How to migrate SVN branches and tags to TFs git Branches and tags along with trunk?

    ReplyDelete