简体   繁体   中英

Cloning a git-from-svn repository and getting all the remote branches

I'm struggling to understand how to be able to clone a git repository from Subversion, and then clone that repository to another machine (git-to-git) and still have access to all the original Subversion branches and tags. Here's what I've done, and where I'm running into roadblocks.

First, on machine A, I cloned my Subversion repository into a git repository:

[machine A]$ git svn clone -s http://svn.repo.url/MyProject

That gave me a git repository with the entire history and all the branches and tags of my original Subversion repository:

[machine A]$ git branch -r
* master
  remotes/v1
  remotes/v1.1
  remotes/v1.2
  remotes/test_migration
  remotes/tags/20100104
  remotes/tags/20100308
  remotes/trunk

Now, on machine B, I want to clone that git repository, and still have access to all the original Subversion branches and tags. First, I cloned the repository:

[machine B]$ git clone machine.a:git/MyProject

This got me a clone of the git repository... but I don't see any of the remote branches or tags:

[machine B]$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

No matter what form of git checkout --track -b [branch] origin/[branch] I try, I can't get a branch created on machine B that tracks one of the remote, originally-from-svn branches... nor does a git svn fetch , git svn pull , or anything else I can try pull in the remote branches and tags from the repository on machine A. what am I doing wrong?

I think this is because git doesn't clone remote branches by default. Configure your clone with this command

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

before you do the initial git fetch to clone the original repo. See the docs for details (search for the string above to find the explanation).

Also read the section "CAVEAT". Subversion isn't git and there are some important differences which you must understand or you will corrupt either your git or your svn repo.

I wanted to comment on this answer but I'm not allowed yet so I have to post a new one.

Pay attention that after cloning the svn remotes you have to init them locally, which is described in the docs. However, citing the docs:

be sure to use the same URL and -T/-b/-t options as were used on server.

git config -l | grep remote git config -l | grep remote will list all configuration for all remotes (url, branches, ignore etc.) on the host repository. The output will be similar to:

svn-remote.svn/bbpress.url=http://svn.automattic.com/bbpress/trunk
svn-remote.svn/bbpress.fetch=:refs/remotes/svn/bbpress

Then add it to, say, .gitignore (commenting with # and replacing = with a space) for future reference. After cloning use git config --add with this info, and you'll get the exact copy of those remotes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM