Wednesday, November 18, 2015

Welcome Git, Thanks SVN!

First, I have to said that this is a late welcome, because Git has many years, I think 10 years as I'm writing this guide.

Several years have passed since I worked with different SCM, I started using CVS, then I migrated to SVN. Yes I'm think I'm getting older.

Since SVN, I thought there was nothing better and simpler until I get to know Git. First I said, why I should bother to migrate, this could be very tedious and long work, but let's face it, once you start using Git you'll never want go back.

But enough talking, here are the steps on how did I migrate from SVN to GIT my repositories.

Migrating from SVN to GIT


1. Checklist

You will need the following:

  1. Git installed in your system
  2. SVN installed in your system
  3. git-svn installed
  4. An SVN Repository you will migrate

2. Check git-svn


$ git svn --version
git-svn version 2.6.2 (svn 1.7.20)
If you don't have it installed you will see something like this:
$ git svn --version
git: 'svn' is not a git command. See 'git --help'.

Did you mean one of these?
 fsck
 show
Don't worry, if you are in Ubuntu, just hit this command:
$ sudo apt-get install git-core git-svn

3. Create Users File

You will need a file to map each user from SVN to Git.
For this guide create: users.txt

jdoe = John Doe 
pepe = Jose Perez 
bob = Bob Doe 
To see all users, on the existing SVN repository run this command:
$ svn log --xml | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = /'

4. Clone SVN repository

Warning: Depending on the size of your repository this could take a long time so you should sit tight.

If you have an satandard layout, as

  • trunk
  • branches
  • tags
You can use option --stdlayout like: In my case I had some troubles, because I had some branches not under branch, something like this:
  • trunk
  • trunk-old
  • branches
  • tags

5. Check the repository

Go to your new new repo directory "project1-tmp".
Check all branches with:

  $ git branch -la
In this step you will have several Git branches:
  • branches like remotes/branch1, remotes/branch2, ...
  • tags like remotes/tags/tag1, remotes/tags/tag2, ...

6. Fix tags

SVN "tags" are no different than branches, and with this command you will create a Git tag and delete every branch that starts with remotes/tags/* Run this command to create Git tags:
Now check your tags and branches with

  $ git tag
  $ git branch -lr

7. Fix Branches

If you want to keep branches you should create a local branch for each remote branch. For exampe:

  $ git checkout -b local_branch remote_branch
You can use this script to generate shell commands (copy & paste), and then remove the ones you don't want. Don't forget to skip master.

8. Share your repository

Now you can change to a service like GitHub or BitBucket. Adding the origin and later push branches and tags. Replace URL: with your actual repository



References:

No comments:

Post a Comment