Showing posts with label svn. Show all posts
Showing posts with label svn. Show all posts

2010-02-15

Migrate a Git repo to a SVN one

We often see the opposite, convert a SVN repository into a Git one and try the breeze of a DVCS, but what if you want to convert a Git repo into a SVN one?

The process is not easy (and you need a "straight" Git repo: no merge, too complex branches and so), and the result is quite raw, but you're still able to convert the main part into SVN. Here are the steps:
  1. create an empty SVN repository: svn mkdir svn://path/to/repo/project/{trunk,branches,tags}
  2. clone it in a Git repo: git svn clone svn://path/to/repo/project --stdlayout . This will create a project directory, empty except for the .git information directory; master is the default Git branch created by git-svn that maps SVN trunk.
  3. cd project
  4. add the original Git repo as a remote: git remote add origin git://uri/to/git/repo/project.git
  5. fetch from it: git fetch origin
  6. create a local branch for the remote master: git checkout -b old_master origin/master . Note that master branch is already present, so we define another one.
  7. being on old_master we rebase this branch onto master: git rebase --onto master --root . Doing this, we have "moved" all our commits from old_master to master
  8. and push all the commits into the SVN repo: git svn dcommit
It's not that elegant, but it gets it done. I'd like to know if someone is aware of a better method, also to import tags and branches, that this process doesn't do.

UPDATE: added 'cd project' step 2