CVS/SVN conversion to Git

The are many ways to convert a CVS/SVN repository to a Git equivalent. The following guide will describe the method found by the KTH IT department, to be the most feasible, for most users. It seems to be the most user friendly while at the same rather conservative when it comes to preserving revisions, history etc.

The simplest method is to use porter.github.com  and the clone the project to KTH GitHub. But this can only be used for small prject do not need to be restricted from the general public. In the future this feature may be available directly by KTH GitHub.

For those inclined there is also cvs2git/svn2git, it is the least user firendly but the most powerful method.

The preferred method chosen the the KTH IT department is the built-in svn import command of the GitHub client. It is a two-step process; first you import (clone) the SVN-project as a local Git repository. Then you upload (push) the local, converted repository, to an empty pre-created repository at KTH Github.

The following guide will:

  • Assume that you have installed GitHub for Windows or GitHub for Mac (including the terminal tools for Mac, which will also require XCode).
  • Assume that you have already setup your SSH keys correctly.
  • Assume (for the sake of simplicity) that you have created a subfolder named "gitrepos" at the root of your system partition, i.e. C:\gitrepos (on Windows) or /gitrepos/.
  • (For a real-world example) show how to import/convert the Filezilla svn repository into KTH GitHub.

1. Login to your KTH GitHub website (in the example it will be user brain, on gita.sys.kth.se):

Student: gits-15.sys.kth.se
Staff: gitr.sys.kth.se
Administrative staff gita.sys.kth.se

2. Create an empty repository for SVN the project you wish to import (referred to as "kthzilla" in the example).

3. Start a "GIt Shell" (should be in the "Start menu" if using GitHub for Windows), or the terminal if using GitHub for Mac OS X .

4. Go to the folder you wish to import the SVN project to (or create one in the shell/terminal). Then run the command:

 git svn clone [address to remote svn repository] [local name]

In our example it is:

git svn clone https://svn.filezilla-project.org/svn/FileZilla3/trunk filezilla

If the command is run from C:\gitrepos (on Windows) or /gitrepos/ (on Mac) it will result in a local git repository locate in

C:\gitrepos\filezilla (on Windows) or /gitrepos/filezilla (on Mac)

If [local name] ("filezilla" in the example) is omiited the name of the subfolder will instead be:

C:\gitrepos\trunk (on Windows) or /gitrepos/trunk (on Mac)

IMPORTANT NOTICE:

The import step may take a very long time to complete, and thus it maye also be interrupted during the download. To resume an import, run the following two commands:

cd [local name] ("cd filezilla" in this example)
git svn fetch

5. Now go inside the projekt folder by running:

cd [local name] ("cd filezilla")

6. Then run the following commands:

git branch -l (will show you what branch name [master/origin] to use in the the next command)
git remote add [master/origin] git@[server-name]:[kth.se-username]/[gitreponame].git
git push -u [master/origin]

which in the in our example is:

git branch -l (output shows "*master")
git remote add master git@gita.sys.kth.se:brain/kthzilla.git
git push -u master

Assuming everything runs as it should, once the push is complete, the project should be in the "empty" repsitory that was created on KTH GitHub.

Hjälpte denna sida dig?
Tack för din åsikt!
Innehållsansvarig:it-support@kth.se
Tillhör: KTH Intranät
Senast ändrad: 2019-03-08