breaking into the unknown…

steps to move from git to svn

Leave a comment

I have been working with Git for long, but recently client asked to move the repository to SVN. I do not know, what benefits it will give over Git . Personally, I prefer working with git and find it better in managing my source code. A comparative analysis of commands used in both is available here . The one clear distinction between git and svn is that, in Git your code history is maintained both locally and remotely i,e say you are working on master branch locally, so when you do git diff it will compare changes from your local master branch rather than the remote master branch,  but with svn all history are maintained at some detached remote branch, and when you do diff , it compare the changes from that remote branch. Anyway, I follow the below steps.

STEP 1: Install svn in your system

$ sudo apt-get install svn

STEP 2: check that svn working properly

$ svn -h # It will list all the commands you can use with svn, You can use it whenever you want to know about a svn command

   blame (praise, annotate, ann)
   changelist (cl)
   checkout (co)
   commit (ci)
   copy (cp)

You can apply on any of these command to know more about them

$ svn ci -h # so it will tell about ci command
commit (ci): Send changes from your working copy to the repository.
Valid options:
  -q [–quiet]             : print nothing, or only summary information
  -N [–non-recursive]     : obsolete; try –depth=files or –depth=immediates
  -m [–message] ARG       : specify log message ARG
  -F [–file] ARG          : read log message from file ARG
  –force-log              : force validity of log message source

STEP 3: hosting ths SVN repository

This part is need to done by the client. There are a number of  service provider there like Assembla, Unfuddle , BeanStalk, CVSDude, ProjectLocker ,  etc. Go to any of them, create a account and get the url of the empty svn repository to which the developer will push there code . say you are provided  with below url by the client

STEP 4:  cloning the svn repository

$ cd Projects # I keep all my projects in this folder

$ svn checkout    arun-finance # so the code will copy to arun-finance folder, if not given name it will be copied with the repository name i,e my-finance

$ cd arun-finance # it contain only a .svn folder as no code is added to it yet

STEP  5:  Adding Files to SVN

I copied all the file from my local git repository except .git and .gitignore folder to this folder(now git is not needed)

$ svn status
?       db
?       Gemfile_back
?       spec
?       public
?       test
?       product.xml
?       app

The ? marks in svn means the file are untracked i,e not yet added to svn

$ svn add .
svn: warning: ‘.’ is already under version control # as the empty repository I cloned already have a .svn folder, so I added them as below

$ svn add script config lib Gemfile README.textile features public test product.xml app log Rakefile  Gemfile_back spec coverage vendor Gemfile.lock db

$ svn status
A       README.textile
A       public
A       public/favicon.ico
A       public/document_viewer
A       public/document_viewer/document_viewer.js
A       public/system


A       log/development.log
A       log/thin.log

So all files are now added to svn, but I have added lof file also, I do not want that so reverted as below

$ svn rm log –force # I have added log to svn, but not want it so reverted back

STEP 6 :  Pushing the code to the remote repository

$ svn ci -m”repository moved from git to svn”
Authentication realm: <; Subversion Repository
Password for ‘arun’: # give your system password
Authentication realm: <; Subversion Repository #
Username: arun123
Password for ‘arun123’: # the password with which you access the remote repository
Adding         Gemfile
Adding         Gemfile.lock
Adding         Gemfile_back


Transmitting file data ……………………………………………………………………………………………………………………..Committed revision 1.

So,  Your code is now available at the remote repository. You can see it your self by going to the repository url in the browser

$ svn up # this will update any change in the remote branch to your local branch
At revision  1.

STEP 7 : Deploying  remote svn repository to server

You can write deployment script for it, but for time being I did it manually. The logic is simple, You just need to login to your server and replace the source code taken from git earlier to the code pulled from the new svn repository.

$ ssh root@ # my server ssh path
root@’s password: year206
[root@cms05 ~]# cd ~/loan_projects

[root@cms05 loan_projects]# ls # showing the folder hosted with git


[root@cms05 loan_projects]# cp -R my_finance my_finance_git # backup the folder as my_finance_git, to revert back if anything goes wrong

[root@cms05 loan_projects]# rm -rf my_finance # You need to clone ths svn with the name of folder you are removing as your nginx or the other server is configured to read the source code from this folder, if name get changed you need to make change there also, to make it work again

[root@cms05 loan_projects]# svn checkout   my_finance

[root@cms05 loan_projects]# cd my_finance

[root@cms05 my_finance]# svn up # It will update the recent code from remote. run it evertime you want to deploy the recent code

[root@cms05 my_finance] #   move to the my_finance folder and run all the command you run earlier before restarting your server

[root@cms05 my_finance]# sudo /etc/init.d/nginx restart # restart the server

Now, Go to your site in browser, It is up as usual


Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s