-3

I am trying to migrate from SVN to git on windows by downloading the svn2git.sh script file and using the following command.

sh svn2git.sh [ProjectName] [SVN Repo link] [SVN Rev (Probably 0)] [Stash Repo Link]

I am new to this and very confused between git-svn and svn2git usage. Can anyone suggest me the steps for svn to git migration using svn2git tool?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Java99
  • 1
  • 3

2 Answers2

1

I created a script for svn to git migration. This script migrates the svn repo to git along with all it's tags and history maintained.

Pre-requisites : Make sure GIT and SVN are installed on your machine before moving ahead with the migration.

Description for Variables used

SVN_REPO_LINK : http link to where you svn repo is hosted

GIT_REPO_NAME : the name that you want to give to you new git repo

GIT_REPO_LINK : link to your git server where you want to host the repo. [It is basically a GIT remote that you would want to add]

Authors File : In svn the commits are associated with the username only, but in git repository email address is also required besides the username. Inorder to maintain the svn commits in git, user emails are are needed. This file serves that purpose. The format of the file is as follows :

svn user name = Name <email>

Helen_david = Helen David <helen.david@mycompany.com>

RobinR = Robin Rose <robin.rose@mycompany.com>

Script

git svn clone --stdlayout --prefix 'svn/' -A authors.txt $SVN_REPO_LINK $GIT_REPO_NAME
cd $GIT_REPO_NAME

git for-each-ref refs/remotes/svn --format="%(refname:short)" | sed 's#svn/##' | grep -v '^tags'| while read aBranch; do git branch $aBranch svn/$aBranch; done
git branch -d trunk 
git for-each-ref refs/remotes/svn/tags --format="%(refname:short)" | sed 's#svn/tags/##' | while read aTag; do git tag $aTag svn/tags/$aTag; done
git remote add origin $GIT_REPO_LINK
git push -u --all origin
git push --tags origin

Now your repository is migrated along with all it's tags,branches and history.

Ambreen Sh
  • 11
  • 1
0

I had to migrate from SVN to git, and I found a really useful tutorial in atlassian. It shows you step by step how to migrate to git, in fact there is a svn-migration-scripts.jar that helps you with the process and this preserve your tags and branches, this is the link: https://www.atlassian.com/git/tutorials/migrating-overview.
And at the end you don't need to create a bibucket account, you can use github. Some of the command line changed in my case, for example I had to authenticate with user and pass when I created the authors.txt in convert step - Standard SVN layouts, so I added the user name at the end, more info in https://bitbucket.org/atlassian/svn-migration-scripts/src

 java -jar  <your path>/svn-migration-scripts.jar authors https://<svn_repo>/<project>/ <username> 

I skipped some of the steps, for example Synchronize process- Update the authors file, Automatically generating Git authors, Fetch the new SVN commits, Synchronize with the fetched commits, Clean up the Git repo (again), because in my case I did't need to commit in svn during the transition. It depends if you are working with more developers or not, and how fast you get use to git.

I also had to configure the ssh-key in the repo just in case that you need it. https://help.github.com/articles/generating-ssh-keys/

I hope this help you

Jan
  • 935
  • 8
  • 20