Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible to recreate svn repository from (full) git-svn clone?

Tags:

git

svn

git-svn

As title, is there any way to reconstruct a svn repo from a full clone with git-svn (containing every single commit starting from r1)?

Edit:

I probably should add that I am looking for a practical means to do it (near-perfect copy is okay as long as it remains usable just as the original svn repository)

like image 700
prusswan Avatar asked Nov 08 '12 07:11

prusswan


People also ask

Can SVN git clone from an SVN repository?

Git installation comes with “git svn”. This will allow you to clone a SVN repository and provide a git interface over it. You can clone from a SVN repo using the git svn clone command.

How do I clone a SVN repository?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...

What does git SVN clone do?

The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of your SVN repo, the command needs to be configured differently.


2 Answers

Yes, it's possible to create an SVN repository rather close to your git-svn repository (even restoring svn:mergeinfo from Git merge commits and svn:ignore from .gitignore). The steps to do that:

1.Prepare branches and tags:

Create refs/heads/* for every refs/remotes/* (current refs/heads/* positions will be lost):

$ git branch -a | awk '/remotes\/([^\/])+$/{ref=substr($1, 9); system("git update-ref refs/heads/" ref " refs/remotes/" ref )}'

or you can set refs/heads/* for all interesting branches manually

Note that refs/heads/master is mapped to SVN trunk but the script above will set refs/heads/trunk to refs/remotes/trunk. So after running it one should set refs/heads/master to refs/remotes/trunk and delete refs/heads/trunk:

$ git update-ref refs/heads/master refs/remotes/trunk
$ git branch --delete refs/heads/trunk

The same about tags: set refs/tags/* to refs/remotes/tags/* positions:

$ git branch -a | awk '/remotes\/tags\/([^\/])+$/{ref=substr($1, 14); system("git update-ref refs/tags/" ref " refs/remotes/tags/" ref )}'

Check that all refs/remotes/* and refs/remotes/tags/* are converted to refs/heads/* and refs/tags/* because only these references will be converted.

2.Create an empty SVN repository

$ svnadmin path/for/svn/repository

3.Create a bare Git repository containing refs/heads/* and refs/tags/* prepared at step 1:

$ git clone --bare path/to/git-svn/repository path/for/svn/repository/.git

4.Download and install SubGit using this link (intermediate build that removes "git-svn-id:" signatures from Git commits messages while converting). In general, SubGit is not free but for one shot conversion (your case) it can be used for free. Convert the repository with SubGit (it expects to find the Git repository at path/for/svn/repository/.git)

$ subgit install path/for/svn/repository

5.After SubGit installation Git and SVN repositories will be kept in sync. Optionally to break bi-directional synchronization (you can enable it any time), run

$ subgit uninstall path/for/svn/repository
like image 95
Dmitry Pavlenko Avatar answered Sep 28 '22 00:09

Dmitry Pavlenko


In theory, it is possible to recreate a repository that is very close to the original Subversion repository. However, there are some aspects of Subversion repository data (such as properties and mergeinfo) that is not cloned by git-svn. Therefore you won't necessarily be able to recreate an exact copy of the original.

like image 22
Greg Hewgill Avatar answered Sep 28 '22 00:09

Greg Hewgill