Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a git-svn repository with svn metadata

Tags:

git

svn

git-svn

I've cloned my main repository with git-svn clone svn://url/trunk --stdlayout. Now I want to clone the repository, with the svn meta data. So that I'll be able to git-svn rebase it to the main server.

Note, I don't want to push commits between two git-svn clones, I simply want to add all the git-svn metadata to the newly cloned repository, so that the new clone will be able to communicate with the main subversion server as well.

like image 656
Elazar Leibovich Avatar asked Mar 17 '11 13:03

Elazar Leibovich


People also ask

How do I clone a git repository in SVN?

# 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 ...

Can I use git and SVN at the same time?

No interaction between them. Just ignore the . git folder for SVN and the . svn folder for Git and you should be fine.

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

It's in the docs. What you should do is:

git config --replace-all remote.origin.fetch '+refs/remotes/*:refs/remotes/*' git fetch 

to fetch the svn meta-branches. Then you'll be able to git-svn rebase without fetching everything from scratch.


Quoting from the docs:

The initial git svn clone can be quite time-consuming (especially for large Subversion repositories). If multiple people (or one person with multiple machines) want to use git svn to interact with the same Subversion repository, you can do the initial git svn clone to a repository on a server and have each person clone that repository with git clone:

# Do the initial import on a server         ssh server "cd /pub && git svn clone http://svn.example.com/project # Clone locally - make sure the refs/remotes/ space matches the server         mkdir project         cd project         git init         git remote add origin server:/pub/project         git config --replace-all remote.origin.fetch '+refs/remotes/*:refs/remotes/*'         git fetch # Prevent fetch/pull from remote git server in the future, # we only want to use git svn for future updates         git config --remove-section remote.origin # Create a local branch from one of the branches just fetched         git checkout -b master FETCH_HEAD # Initialize 'git svn' locally (be sure to use the same URL and -T/-b/-t options as were used on server)         git svn init http://svn.example.com/project # Pull the latest changes from Subversion         git svn rebase 
like image 68
Elazar Leibovich Avatar answered Sep 19 '22 02:09

Elazar Leibovich


Super-fast simple copy-clone between remote machines

From the docs:

'git clone' does not clone branches under the refs/remotes/ hierarchy or any 'git svn' metadata, or config. So repositories created and managed with using 'git svn' should use 'rsync' for cloning, if cloning is to be done at all.

A copy-clone on the same machine can simply be done using cp -rp <src> <dst>, and from a remote machine using scp -rCp <src> <dst>.

However, the remote case can be very very slow (10 minutes even on ethernet) because of the large number of tiny files it has to copy.

Using cpio you can avoid this overhead, meaning (depending upon bandwidth) it just takes a few seconds (for a 100Mb git repo on a 50Mbit/s connection).

ssh -C <user>@<host> "cd <path to parent dir of repo>; \ find <repo directory name> -depth -print | cpio -oa" | cpio -imd 

For example

ssh -C alex@myhost "cd ~alex/repos/; \ find WonderProject -depth -print | cpio -oa" | cpio -imd 

results in a new git repo 'WonderProject' in the current working directory on the local machine.


(note that the documentation I refer to almost denies the existence of the section @Elazar refers to, so I'm not discrediting @Elazar's excellent solution, but looking for a more concise memorable one)

like image 20
Alex Brown Avatar answered Sep 21 '22 02:09

Alex Brown