Wednesday, January 01, 2014

Migrate from SVN to Git/Github

Today I migrated the PyFileServer codebase from its original home in SVN on BerliOS to Github, without losing commit history

Here's how I did it.

First, I created a git version of the SVN repository locally using git-svn.
The first thing you need is a text file (users.txt) that maps your SVN users to Git/Github users, in the format:
user1 = First Last Name <email@address>

then you call:
/fs/migration> git svn clone --stdlayout -A users.txt svn:// pyfilesync
the --stdlayout flag indicates that the SVN repository follows the trunk/branches/tags standard structure, which aids in identification of branches. Git-svn will pull the commits from SVN and populate them in your repository as Git commits. Note: If it meets a user that is not in your users.txt file, the process will stop, but you can always fix the users.txt file, and then peruse into the repository and use "git svn fetch" to resume the process (you don't have to re-specify the users.txt location when calling git svn fetch).

This process automatically copies over the svn trunk as the local git master, but the svn branches and tags remain in the git repository as remote branches. To see these branches, use:
/fs/migration/pyfilesync> git branch -r

to "copy" the remote branches over as local branches, use:
/fs/migration/pyfilesync> git checkout -b <new local branch name> <remote branch name>
/fs/migration/pyfilesync> git checkout -b code-review code-review
/fs/migration/pyfilesync> git checkout -b paste-prune paste-prune
SVN tags are also copied over as branches, and you have to re-tag them as Git tags if you wish.

Next, I created the Github repository project, and then cloned it onto my local computer.

/fs/migration> git clone

At this point I have my svn-import git repo at /fs/migration/pyfilesync, and my Github-cloned git repo at /fs/migration/pyfileserver

Then I went into the pyfileserver git repository, and added the pyfilesync repository as a remote repository:
/fs/migration/pyfileserver> git remote add -f svnimport ../pyfilesync
and merged the changes in the master branch (the pyfileserver repo is currently on master)
/fs/migration/pyfileserver> git merge svnimport/master
You have to bring over the remaining branches as well
/fs/migration/pyfileserver> git checkout -b code-review svnimport/code-review
/fs/migration/pyfileserver> git checkout -b paste-prune svnimport/paste-prune

Finally, I push the new commits on the local pyfileserver git repository back to Github. All done!

The general schematic of what I did above looks like this:


1 comment:

jake george said...

Git and Github Online Training
Familiarization with Git and DVCS concepts; Introduction to the Github platform; Repository creation on the web and desktop; Document versioning with local ...
Call Us +919000444287 or