2010-02-15

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:

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.

cd project

add the original Git repo as a remote: git remote add origin git://uri/to/git/repo/project.git

fetch from it: git fetch origin

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.

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

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.

Hi, I cannot reproduce your steps. When i get to the rebase, git prints out a very odd message:

warning: squelched 210 whitespace errorswarning: 215 lines add whitespace errors.Falling back to patching base and 3-way merge...error: Your local changes to 'MonitorVendite.BLL/MonitorVendite.BLL.csproj' would be overwritten by merge. Aborting.Please, commit your changes or stash them before you can merge.Failed to merge in the changes.

How is it possible to have local changes if I only checked out remote commits?