10

Yes, I know. Why would you want to migrate from Git to SVN?

Well I happen to be in a situation that I need to migrate a huge Git repo to Subversion! Here's one workflow I tried per Edwin's comment:

first create a local SVN repo: svnadmin create svn_repo

Next I check out my Git repo: git clone git:myNameSpace/myProject

cd into the myProject and run:

git svn init -s --prefix=svn/ file:///home/myHome/svn_repo/myProject

git svn fetch

git rev-list --parents master | grep '^.\{40\}$' to look up the hash of your root commit and gives only one commit as it should.

Next is to get the hash of the empty trunk commit: git rev-parse svn/trunk

This one unfortunately fails with:

fatal: ambiguous argument 'svn/trunk': unknown revision or path not in the working tree. Use '--' to separate paths from revisions

Well I can't go much after this....

Reza Toghraee
  • 1,603
  • 1
  • 14
  • 21
  • 7
    There is a lot of marketing (and a few good reasons) to favor Git over Subversion, but there are a lot of very good reasons to favor Subversion over Git too. Sane large file handling comes to mind (for one reason). – Edwin Buck Apr 04 '12 at 15:17
  • Sure, I love Git and favor it to Subversion in a heart beat... but I need to do this migration anyway... – Reza Toghraee Apr 04 '12 at 15:19
  • 1
    Actually, I favor subversion over git, but that has more to do with my familiarity, and tool integration expertise with subversion. It has little to do with git's feature set. – Edwin Buck Apr 04 '12 at 15:26
  • 1
    LOL, got it. It's the other way for me with Git I suppose... – Reza Toghraee Apr 04 '12 at 15:58
  • 2
    SVN 4 ever :) On additional reason: After committing code can't forget to "push" ... – hfrmobile May 16 '13 at 15:34
  • possible duplicate of [Pushing an existing git repository to SVN](http://stackoverflow.com/questions/661018/pushing-an-existing-git-repository-to-svn) – Kristopher Johnson Jul 24 '14 at 19:54

2 Answers2

8

I would recommend you to migrate that with SubGit in several easy steps.

$ svnadmin create svn.repo
$ subgit configure svn.repo
$ nano svn.repo/conf/subgit.conf #edit path to your (bare!) Git repository (you may use "git clone --bare <URL> bare.git.repo" if you don't have it locally)
$ subgit install

That's all. While translation SubGit will try to preserve all commits (even temporary), branches, merges, ignores, dates, EOLs settings, tags and so on, as it it possible.

After translation the repositories will be in sync (each push to Git is translated to SVN revision and vice versa). To break synchronization (if you don't need it) run

$ subgit uninstall svn.repo
Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38
  • 1
    Note that SubGit requires server-side configuration (i.e. the 'svn.repo/conf/subgit.conf' file), so it's of no use if you don't have access to the server itself. – Siggen Nov 27 '12 at 10:35
  • 1
    Since 2.0 one can do the same with the remote repository using `subgit configure --svn-url `. Or alternatively (a better way, if pre-revprop-change hook allows) one can convert the repository locally and upload it using `svnsync` or `svndump+svnrdump`. – Dmitry Pavlenko Dec 01 '12 at 00:01
  • will SubGit erase all the SVN history, or it's only going to create additional revisions based on the git commits? – igorsantos07 Mar 04 '13 at 07:39
  • 1
    There's no way to erase SVN history by design, one can only create a new SVN repository with another history, so SubGit erases nothing, only creates additional commits. SubGit 1.0.x translates Git commits only to an empty repository; SubGit 2.0 allows to translate Git commits to non-existing project URL, creating it and not touching other projects. – Dmitry Pavlenko Mar 04 '13 at 10:02
3

--- Edited after details added ---

Did you do an empty initial commit to svn/trunk? If not, then it would explain why you get an error that it cannot be found in the history.

The comments (in combination)

The --prefix gives you remote tracking branches like "svn/trunk" which
is nice because you don't get ambiguous names if you call your local
branch just "trunk" then. 

and

Then get the hash of the empty trunk commit:

Tends to imply that they made a svn/trunk commit to prevent svn conflict with a pre-existing trunk directory. If that is so, perhaps your only misstep is not committing a svn/trunk to be found later?

--- Original post follows ---

Have you tried this? dcommit won't work properly until you linearize your trunk (or branch) history.

Please post the details of your attempted migration. While what you posted is a useful error message, it would be ten times more useful with the list of steps you used to arrive at that error.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • the `git svn fetch` fails with: W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 1, path '/gentkt' W: Do not be alarmed at the above message git-svn is just searching aggressively for old history. This may take a while on large repositories – Reza Toghraee Apr 04 '12 at 20:23
  • and then the `git rev-parse svn/trunk` gives: svn/trunk fatal: ambiguous argument 'svn/trunk': unknown revision or path not in the working tree. Use '--' to separate paths from revisions – Reza Toghraee Apr 04 '12 at 20:23
  • Edwin, I updated the question posted and the steps I had took per you link. Thanks for the help and please let me know if I could do more. – Reza Toghraee Apr 04 '12 at 20:54
  • @RezaToghraee i updated my answer. It is a bit of a guess, as I am not overly familiar with git, but maybe you know git well enough to see if it is obviously wrong. – Edwin Buck Apr 04 '12 at 21:31