Migrate an SVN repository to Git While Maintaining Branches and Tags Structure
Git is awesome, but for our Rails projects, we like to follow a similar “centralized repository model” that SVN makes use of.
We want to use distributed Git repositories, with one central “shared” repository to use for deployments, etc.
We don’t want to use Git with a shared SVN repository. (git-svn)
And, we have a bunch of SVN repositories already that we need to migrate to Git repositories.
I’ll describe what I did to make this happen:
Notes, quotes, credits all from: http://notahat.com/posts/25
This is a great post to follow, and accounts for most everything I did here.
The difference is that I’m using svn2git, instead of doing manual git clone commands.
The above post will only set up remote branches, and what I wanted was to have all branches and tags local to my new Git repository.
Svn2git will copy all of your branches / tags from the original SVN repository into your new Git repository as well.
(Check it out here [thanks to nirvdrum]: http://github.com/nirvdrum/svn2git/tree/master)
Let’s say I have an SVN repository structured as:
trunk
...
branches
1.x
2.x
tags
1.0.0
1.0.1
1.0.2
1.1.0
2.0.0
Our goal is to have a git repository with native tags/branches taken from our SVN repository.
At the end of my migration, I want my Git repo to look like:
$ git branch
* master
1.x
2.x
$ git tag -l
1.0.0
1.0.1
1.0.2
1.1.0
2.0.0
#Make sure Git is installed:
#If you don’t have the epel yum repository enabled by default, you must specify to enable it at the command line:
#For other distributions, you know the drill (apt-get, port, etc.)
yum --enablerepo epel install 'git'
yum --enablerepo epel install 'git-svn'
#Now, create a system git user and group
sudo adduser git
#Now edit /etc/group, and add any users who’ll need to access the Git repository to the git group:
...
git:x:100:james,paul
...
#Make a directory for Git repositories
#We chose: /usr/local/git_root
sudo mkdir /usr/local/git_root
sudo chown git.git /usr/local/git_root
sudo chmod 2770 /usr/local/git_root
#Create your svn-authors.txt in /usr/local/git_root/svn-authors.txt to tell Git how to convert SVN usernames in the logs:
#Place *ALL* SVN authors in this file so that git doesn’t complain when it cannot find a particular user to convert.
pbunyan = Paul Bunyan <pbunyan@example.com>
jbond = James Bond <jbond@example.com>
On the left are the Subversion user names; on the right are the Git equivalents.
#Make sure your gem sources include github.com (if necessary)
sudo gem sources -a http://gems.github.com
#Install the svn2git gem
sudo gem install nirvdrum-svn2git
#Verify that you have svn2git in your PATH
which svn2git
#We will create a temporary directory in /tmp/
#This is where we will fetch the SVN repo into a git repo.
#We’ll then use this temporary repo to create our bare repository.
mkdir /tmp/foo-project
cd /tmp/foo-project
#I’m assuming you have the standard SVN setup of
-root
---trunk
---branches
---tags
If not, you can look into the options of svn2git to match your SVN repo structure.
#Run the command given your svn-authors file:
svn2git https://svn-repo/foo-project --authors /usr/local/git_root/svn-authors.txt
#You can go into this folder and verify that you see all your local branches and tags by running:
git branch
and
git tag -l
This should print out the lists of your branches and tags if everything is working right so far!
Next, we want to create our bare repository in /usr/local/git_root.
#Become git user and set permissions
sudo su - git
cd /usr/local/git_root/
umask 007
#Clone the temporary repository created by svn2git to a bare repository.
#<project>.git is a local convention.
git clone --bare /tmp/foo-project foo-project.git
cd foo-project.git/
#Make sure permissions are set properly
git config core.sharedrepository 1
git config receive.denyNonFastforwards true
find objects -type d -exec chmod 02770 {} \;
The core.sharedrepository flag tells git to keep everything group readable and writable.
The receive.denyNonFastforwards flag makes sure that merges can’t happen when you push to the repo. You have to do the merges on your local machine, and then push the result.
#Try to do a git clone from your workstation (another computer)
git clone ssh://git-repo:22/usr/local/git_root/foo-project.git
#Clean up
Once you’re happy that everything is working, delete the temporary repo that you created in /tmp, and you’re done!
[...] http://qugstart.com/blog/git-and-svn/migrate-an-svn-repository-to-git-while-maintaining-branches-and... [...]
PieterVogelaar.nl » Convert SVN to GIT bare repository
10 Sep 11 at 1:39 pm
Hi Andrew, this a useful post, it would be very useful if tags could be migrated automatically. Unfortunately svn2git doesn’t work for me:
$ sudo gem install svn2git
Successfully installed svn2git-2.2.2
1 gem installed
Installing ri documentation for svn2git-2.2.2…
Installing RDoc documentation for svn2git-2.2.2…
$ svn2git
/usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:247:in to_specs’: Could not find svn2git (>= 0) amongst [actionmailer-3.2.1, actionmailer-3.1.0, actionpack-3.2.1, actionpack-3.1.0, activemodel-3.2.1, activemodel-3.1.0, activerecord-3.2.1, activerecord-3.1.0, activeresource-3.2.1, activeresource-3.1.0, activesupport-3.2.1, activesupport-3.1.0, ansi-1.4.2, ansi-1.3.0, arel-3.0.2, arel-2.2.1, bcrypt-ruby-3.0.1, best_in_place-1.0.6, blankslate-3.1.2, builder-3.0.0, bundler-1.0.18, client_side_validations-3.1.4, coderay-1.0.6, coderay-1.0.5, coffee-rails-3.2.2, coffee-rails-3.1.1, coffee-script-2.2.0, coffee-script-source-1.3.1, coffee-script-source-1.1.2, erubis-2.7.0, execjs-1.3.0, execjs-1.2.9, execjs-1.2.8, execjs-1.2.6, ffi-1.0.11, hike-1.2.1, i18n-0.6.0, journey-1.0.3, jquery-rails-2.0.2, jquery-rails-1.0.14, json-1.6.6, json-1.6.1, libv8-3.3.10.4-x86_64-linux, mail-2.4.4, mail-2.3.0, method_source-0.7.1, method_source-0.7.0, mime-types-1.18, mime-types-1.16, multi_json-1.3.2, multi_json-1.0.3, pg-0.13.2, pg-0.12.2, pg-0.11.0, polyglot-0.3.3, polyglot-0.3.2, postgres-pr-0.6.3, pry-0.9.9.2, pry-0.9.8.1, puma-1.6.3, rack-1.4.1, rack-1.3.4, rack-1.3.3, rack-cache-1.2, rack-cache-1.0.3, rack-mount-0.8.3, rack-ssl-1.3.2, rack-test-0.6.1, railroady-1.0.7, railroady-1.0.2, rails-3.2.1, rails-3.1.0, railties-3.2.1, railties-3.1.0, rake-0.9.2.2, rake-0.9.2, rdoc-3.12, rdoc-3.10, rdoc-3.9.4, rubypython-0.6.2, sass-3.1.15, sass-3.1.10, sass-3.1.8, sass-3.1.7, sass-rails-3.2.5, sass-rails-3.1.4, sass-rails-3.1.2, simple_form-2.0.1, simple_form-1.5.2, slop-2.4.4, slop-2.4.3, sprockets-2.1.2, sprockets-2.0.2, sprockets-2.0.0, sqlite3-1.3.6, sqlite3-1.3.4, therubyracer-0.10.1, therubyracer-0.9.9, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, turn-0.9.5, turn-0.8.3, turn-0.8.2, tzinfo-0.3.33, tzinfo-0.3.30, tzinfo-0.3.29, uglifier-1.2.4, uglifier-1.0.3] (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:256:into_spec’
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1208:in `gem’
from /usr/local/bin/svn2git:18
If you have any ideas on how to get this to work please let me know. Thank you.
Luís
22 Jan 13 at 1:54 am
After banging my head a few days I finally came to a recipe that migrates an SVN repo to Git keeping tags with git svn. You can read the deatils here:
http://attheedgeoftime.blogspot.com/2013/01/migrate-svn-repository-to-git.html
Regards.
Luís
25 Jan 13 at 1:47 am