Porting subversion To git
12 April 2017
Before leaving my current role, I was tasked to migrate existing SVN repositories into git. It is exciting since I never did such thing in the past. Funny enough, I was challenged to install git-all
on one of our unregistered Red Hat box. I'm failing to run this command to make base repository accessible. I can raise a ticket to register the box but I'm worried waiting for resolution would take longer than doing the migration on a different machine.
rhn-channel --add --channel=rhel-x86_64-server-optional-6
Anyways, I have to install git-svn
to my personal laptop and do the migration.
$ sudo yum install git-svn
...
Running transaction
Installing : git-svn-1.8.3.1-6.el7_2.1.x86_64 1/1
Verifying : git-svn-1.8.3.1-6.el7_2.1.x86_64 1/1
Installed:
git-svn.x86_64 0:1.8.3.1-6.el7_2.1
Backup and load svn repository
Since I'm going to do the migration on a my personal laptop, I need to dump all the repositories and load them.
$ svnadmin dump /var/svn/ami > airmenzies.dump
$ svnadmin create /home/drmanalo/svn/airmenzies
$ svnadmin load /home/drmanalo/svn/airmenzies < airmenzies.dump
Create committers.txt
Google seach results will give you a one liner to get all the committers.
$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > committers.txt
We only have half a dozen svn users, so I decided to get it from conf/passwd
file of one of the repositories. Format should be like this.
root = root <root@centos.dev>
Clone subversion using git-svn
Here, I'm going to clone an existing svn repository into my home drive folder called temp
.
$ git svn clone file:///home/drmanalo/svn/airmenzies --no-metadata --authors-file=/home/drmanalo/Documents/committers.txt --stdlayout ~/temp
...
r1152 = 8ba77ef334b586dc7560e0bf5be0427f1b255fb8 (refs/remotes/trunk)
Checked out HEAD:
file:///home/drmanalo/svn/airmenzies/trunk r1152
Convert svn:ignore properties into .gitignore
$ cd ~/temp
$ git svn show-ignore -i trunk > .gitignore
$ git add .gitignore
$ git commit -m 'Convert svn:ignore properties to .gitignore.'
Create a bare git repository
$ git init --bare ~/projects/airmenzies.git
Initialised empty Git repository in /home/drmanalo/projects/airmenzies.git/
$ cd ~/projects/airmenzies.git/
$ git symbolic-ref HEAD refs/heads/trunk
### Push to the bare repository
$ cd ~/temp
$ git remote add bare ~/projects/airmenzies.git
$ git config remote.bare.push 'refs/remotes/*:refs/head/*'
$ git push bare master
Counting objects: 32238, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11853/11853), done.
Writing objects: 100% (32238/32238), 37.48 MiB | 53.16 MiB/s, done.
Total 32238 (delta 16197), reused 28310 (delta 14223)
To /home/drmanalo/projects/airmenzies.git
* [new branch] master -> master
You can safely delete the ~/temp
folder.
Push the bare repository
In this instance, I'm pushing the converted svn to my local gitlab
.
$ cd ~/projects/airmenzies.git
$ git remote add origin http://root@localhost/devops/airmenzies.git
$ git push -u origin --all
Password for 'http://root@localhost':
Counting objects: 32238, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9879/9879), done.
Writing objects: 100% (32238/32238), 37.48 MiB | 0 bytes/s, done.
Total 32238 (delta 16197), reused 32238 (delta 16197)
remote: Resolving deltas: 100% (16197/16197), done.
To http://root@localhost/devops/airmenzies.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.