Dec 182012

Yes, you didn’t read it wrong. It says “Migration from Git to Subversion”. Recently, I was forced to migrate from Git to Subversion and I wanted to share my experience here to help anybody forced to do the same. I say “forced”, because I don’t believe anybody will try to migrate from Git to Subversion back willingly.

Let’s start with creating a new Subversion repository:

svnadmin create file:///path/to/subversion/repo

Now we have to create standard Subversion directory structure:

$ mkdir projectname
$ cd projectname
$ svn checkout file:///path/to/subversion/repo/ .
$ mkdir -p {trunk,tags,branches}
$ svn add *
A         branches
A         tags
A         trunk
$ svn commit -m "Creating Subversion repository structure"
Adding         branches
Adding         tags
Adding         trunk
Committed revision 1.

After creating the empty Subversion repository, we have to add this new repository as “remote” to our old Git repository:

$ cd /path/to/git/repo
$ git svn init -s file:///path/to/subversion/repo
$ git svn fetch
r1 = ca449ce813cb935487822967834fc1a3f3ec14f9 (refs/remotes/trunk)

We need these two repositories synched. To do this, we have to point first commit in Git repository to first commit in Subversion repository (ca449ce813cb935487822967834fc1a3f3ec14f9).

But, first we have to find our first Git commit’s hash.

$ git log --pretty=oneline | tail -n 1
7e7a2f7a5df98a79c1e93f809cf7667ff1e114d2 Initial commit

Now, pair them:

$ echo "7e7a2f7a5df98a79c1e93f809cf7667ff1e114d2 ca449ce813cb935487822967834fc1a3f3ec14f9" >> .git/info/grafts

And start synchronization:

$ git svn dcommit
Committing to file:///path/to/subversion/repo/trunk ...
	A	test.php
Committed r2
	A	test.php
r2 = 7921fb344cac9edfb429d2d5d73473d12449e94b (refs/remotes/trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk
	A	bla.php
Committed r3
	A	bla.php
r3 = bd3a6938fdde2fcfcab6c22935ab26017399dbc1 (refs/remotes/trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk

This process depends on how many commits you had in Git repository and how big is your project.

  3 Responses to “Migration from Git to Subversion”

  1. […] I wrote about migrating code from a Git repository to a Subversion repository. Now, I’d like to write […]

 Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>