Converting a Subversion Repository(hosted on Assembla) to a GIT repository (hosted on dedicated Linux Host)
Converting a Subversion Repository(hosted on Assembla) to a GIT repository (hosted on dedicated Linux Host)
We were tasked by our client to move several subversion repositories, hosted at Assembla, to GIT on dedicated internal Linux server. First step was actually installing the Ubuntu Server on their ESXi4 server.
- I downloaded the ubutu 14.04 LTS iso
- Uploaded it to one of the datastores on the ESXi server
- Created a new VM with 4CPU, 8GB RAM and 100 MB disk space.
- I loaded the ubuntu 14.04 iso into the VM CD and started the VM.
- I installed ubuntu with all of the defaults
Next I installed GIT on the server.
- apt-get install git-core
- apt-get install git-svn
Next I clone the svn directory into git.
- git svn clone <svnurl> –no-metadata -A authors-transform.txt –stdlayout /svn/tempreponame/
Ignore the errors about using –prefix, these just caused me headaches and so by NOT using their recommendations to set prefix=origin/ this will work.
Enter your username and password and each time I get an error which says I need to have ‘usera’ I would add usera to users.txt and run the get svn clone command again
- echo “usera = User A <usera@com.com>” >> users.txt
If you receive the error “Unexpected HTTP status 405 ‘Method Not Allowed’ on ‘/svn/wssus.admindash’” this means that you have some protected directories setup in your Assembla. Open the project within Assembla > Settings > Protected branch and remove the directories and run the git svn clone command again
I dont have any ignore files in svn so i fake one
- cd /svn/tempreponame/
- touch .gitignore
- git add .gitignore
- git commit -m ‘Converting Properties from SVN to GIT’ .gitignore
Move the git repository to a new/bare repo and create a symbolic link for the ‘trunk’ coming from SVN
- cd /git/newreponame
- git init –bar
- git symbolic-ref HEAD regs/heads/trunk
Go back to the temporary git repo and push it to the new bar repo and rename the ‘trunk’ to ‘master’
- cd /svn/tempreponame
- git remote add bare /git/newreponame
- git config remote.bar.push ‘refs/remotes/*:refs/heads/*’
- git push bare
- cd /git/newreponame
- git branch -m trunk master
Clean up branches and tags (thanks to http://john.albin.net/git/convert-subversion-to-git for most of this)
- cd /git/newreponame
git for-each-ref –format=’%(refname)’ refs/heads/tags |
cut -d / -f 4 |
while read ref
do
git tag “$ref” “refs/heads/tags/$ref”;
git branch -D “tags/$ref”;
done
Now you have a new repo at /git/newreponame. check it out to confirm it worked by checking it out and confirming that you have the same log history as your original SVN repo
- cd /tmp/
- git clone /git/newreponame
- find . #this should list all of your files
- cd newreponame
- git log