Monday, July 10, 2017

SVN to GIT MIGRATION with Branches and Tags



git svn clone -r1:HEAD -s svnurl svnfolder

git branch
git branch -a


git remote add origin giturl.git

git checkout -b branchname origin/branchname
git checkout -f -b branchname origin/branchname

git push origin master branchname

git checkout origin/tag/tagname
git tag -a tagname -m "creating tag tagname"
git push origin tagname


You can use the following java code if there are too many branches and tags.
Keep all branches in file "branches.txt" and tags in file "taglist.txt"

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class SVNGitMigrator {

 public static void main(String[] args) throws IOException {

  try {

   StringBuilder a = new StringBuilder("git push origin master ");
   File f = new File("branches.txt");
   BufferedReader b = new BufferedReader(new FileReader(f));
   String readLine = "";
   while ((readLine = b.readLine()) != null) {
    System.out.println("git checkout -f -b " + readLine + " origin/" + readLine);
    a.append(readLine+" ");
   }
   b.close();
   
   f = new File("taglist.txt");
   b = new BufferedReader(new FileReader(f));
   readLine = "";
   while ((readLine = b.readLine()) != null) {
    System.out.println("git checkout origin/tags/" + readLine);
    System.out.println("git tag -a " + readLine + " -m \"creating dsp tag " + readLine+"\"");
    a.append(readLine+" ");
   }
   System.out.println(a);
   b.close();
   
  } catch (IOException e) {
   e.printStackTrace();
  }

 }

}

1 comment: