47

Reasons for doing this aside, is there a reasonable way to convert an entire git repository to subversion?

I can find only tons on information on migrating from subversion to git, and exchanging changesets between the two, but not for doing a simple conversion of the entire git repository to svn.

dF.
  • 74,139
  • 30
  • 130
  • 136
  • 1
    Duplicated here: http://stackoverflow.com/questions/661018/pushing-an-existing-git-repository-to-svn/1056817#1056817 – cmcginty Aug 10 '09 at 22:32
  • 23
    Sad that you had to preface with "Reasons for doing this aside" in order to prevent a flame war or such... – Nicu Stiurca Nov 09 '12 at 20:15

2 Answers2

16

The general problem with doing conversions this direction is that Git repositories can contain more than just a linear history of revisions, as Subversion would expect. Multiple ancestries with divergent histories and frequent merge commits are all possible, which can't be easily represented in a Subversion repository.

For simple cases where you do have a linear history in your Git repository, you can use git-svn dcommit to push the lot up to an otherwise empty Subversion repository.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 2
    Sorry to stir this up again after a few years, but can you give a concrete example of how to do this? Say I have a clone of a git repository at ~/my-git-repo, and I want to copy the commit history into some SVN repo, say svn://foo.com/empty-svn-repo/ – Nicu Stiurca Nov 09 '12 at 21:13
  • 1
    @SchighSchagh: Have a look at this recent question, it might be more suited to what you need: [possible to recreate svn repository from (full) git-svn clone?](http://stackoverflow.com/questions/13284762/possible-to-recreate-svn-repository-from-full-git-svn-clone) – Greg Hewgill Nov 10 '12 at 02:44
7

It's very easy to perform with SubGit.

$ svnadmin create svn.repo
$ subgit configure svn.repo
$ nano svn.repo/conf/subgit.conf to specify a path to your bare repository (you may use "git clone --bare <URL>" if you have none locally)
$ subgit install svn.repo

After conversion your SVN and linked Git repository will be in sync: every Git push will be translated to SVN commit and vice versa. To break translation run

$ subgit uninstall svn.repo

While translation SubGit will try to preserve commit dates, tags, ignores, merges, EOLs, branches and so on, as it is possible. I can't say the same about git-svn repository.

Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38
  • 1
    This doesn't work. See https://stackoverflow.com/a/11084905/785194 for a working subgit solution. – EML Jun 14 '17 at 12:14