Non-standard transition from SVN to Git

To keep your history of commits and tags of SVN, you need to use a migration tool. But It can be complex if your SVN is not a standard repository. It’s why I share my experience…

svn-to-git

Most of time you can do a migration out-of-the-box from SVN to Git (via https://git-scm.com/docs/git-svn) at least if your SVN repository follow the standard layout : /branches, /trunk and /tags folders. But it was not my case, I had issues due to my non-standard SVN:

So after some research I find out a blog that explain how to make the transition pain-free only with standard commands and some git configurations. I will explain step by step, what I did to make the migration from my non standard SVN to our new GIT repository, maybe it will help someone else.

* source of the picture : http://www.karpach.com/subversion-to-git-migration.htm

Generate the author file of the SVN users

svn log -q | awk -F ‘|’ ‘/^r/ {sub(“^ “, “”, $2); sub(” $”, “”, $2); print $2″ = “$2″ <userid@mail.com>”}’ | sort -u > authors.txt; cat usersvn.txt

Configure the stagging-local repository with a non-standard SVN layout

  • git svn init [url to svn root] -T branch/[mybranchusedastrunk] -b ” -t tag –prefix=”
  • echo ” branches = {first_folder_in_root_tree}:refs/remotes/*” >> .git/config
  • echo ” branches = branch/{folder_x,folder_y,folder_z}:refs/remotes/*” >> .git/config
  • git config –local –list

Fetch the SVN commits to the staging repo

git svn fetch -A C:/Users/dupont/authors.txt

Create the branch and the tags

git branch -r :

  • git tag -a -m “Converting SVN tags” [tag name] refs/remotes/tags/[tag id]
  • git branch [branch name] refs/remotes/[branch name]

git log

Push the SVN commits to the remote repository

  • git remote add origin [url/repo.git]
  • git push –all origin
  • git push –tags origin

Merge with an existing remote branch

  • git checkout -b development
  • git merge master –allow-unrelated-histories

Configure the cruise control

In the config.xml

< bootstrappers>

< gitbootstrapper localWorkingCopy=”path/to/repo_backend” />
< gitbootstrapper localWorkingCopy=”path/to/repo_frontend” />

< /bootstrappers>

< modificationset quietperiod=”30″ >

< git LocalWorkingCopy=”path/to/repo_backend” />
< git LocalWorkingCopy=”path/to/repo_frontend” />

< /modificationset >

Save the password

Because we have to use https and not the ssh then I had to use this trick even if it’s not super clean :

  • save the password in the cache : git config --global credential.helper wincred
  • clear the cache : git credential-cache exit

Resources

Images from http://www.nsstc.uah.edu/users/phillip.bitzer/coyote_import.html and 
http://www.karpach.com/subversion-to-git-migration.htm


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s