Git: how to convert a SVN repository to GIT
For the conversion we are following the John Albin’s document:
http://john.albin.net/git/convert-subversion-to-git
1. Retrieve a list of all Subversion committers
From the root of your local Subversion checkout, run this command:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform_alpha.txt |
Git require the emails as username, so you have to edit each line:
from:
fred = fred <fred>
to:
fred = fred <fred@archive.org>
for our purpose we can do that quickly running this command:
sed "s/>/@archive.org>/g" authors-transform_alpha.txt > authors-transform.txt |
2. Clone the Subversion repository using git-svn
This will do the standard git-svn transformation (using the authors-transform.txt file you created in step 1) and place the git repository in the “~/temp” folder inside your home directory.
git svn clone svn://home.us.archive.org/petabox -A authors-transform.txt --stdlayout --prefix=origin/ ~/temp |
3. Convert svn:ignore properties to .gitignore
cd ~/temp git svn show-ignore > .gitignore git add .gitignore git commit -m 'Convert svn:ignore properties to .gitignore.' |
4. Push repository to a new project on GitLab
git remote add gitlab git@git.domain.com.au:dev-team/favourite-project.git git push --set-upstream gitlab master |
Congratulations you have done!
—The following instructions are useful only if you are not using GitLab and you want a bare repository—
4b. Push repository to a bare git repository
Then push the temp repository to the new bare repository.
cd ~/temp git remote add bare ~/petabox.git git config remote.bare.push 'refs/remotes/*:refs/heads/*' git push bare |
5. Rename “trunk” branch to “master”
Your main development branch will be named “trunk” which matches the name it was in Subversion. You’ll want to rename it to Git’s standard “master” branch using:
cd ~/new-bare.git git branch -m trunk master |
6. Clean up branches and tags
git-svn makes all of Subversions tags into very-short branches in Git of the form “tags/name”. You’ll want to convert all those branches into actual Git tags using:
cd ~/new-bare.git 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 |