开发者

How do I list and fetch remote branches after SVN to Git migration? [duplicate]

This question already has answers here: How do I migrate an SVN repository with history to a new Git repository? (34 answers) Closed 9 years ago.

I migrated our SVN repository to Git and pushed it to a central repository. We had a fair amount of tags and branches, but somehow we were not able to list and fetch those from a Git client. This was weird, because the tags and branches seemed to be available on the server.

With help from a Jon Maddox blog post, a blog p开发者_如何转开发ost from Marc Liyanage and a SO answer from Casey I was able to stitch a solution together. Thanks for all the help!

Here's what I ended up doing. First I created a file with the svn committers:

local$ svn log svn://server/opt/svn/our_app |grep ^r[0-9] | cut -f2 -d\| |sort |uniq | tee ~/users.txt
alice
bob
eve
local$ vim ~/users.txt
local$ cat ~/users.txt
alice = Alice Malice <alice@malice.doh> 
bob = Bob Hope <bob@hope.doh>
eve = Eve Leave <eve@leave.doh>

Then I created a git repo from our svn repo:

local$ mkdir our_app
local$ cd our_app
local$ git svn init --stdlayout svn://server/opt/svn/our_app 
local$ git config svn.authorsfile ~/users.txt
local$ git svn fetch
local$ git svn create-ignore
local$ git commit -m 'added .gitignore, created from svn:ignore'
local$ for remote in `git branch -r`; do git checkout -b $remote $remote; done  

This last step was crucial, since otherwise branches/tags were not available when cloning from a remote repository. Anyway, I pushed this to a new remote repo:

local$ ssh server
server$ mkdir /opt/git/our_app.git
server$ cd /opt/git/our_app.git
server$ git --bare init
server$ git config core.sharedrepository 1
server$ git config receive.denyNonFastforwards true
server$ find objects -type d -exec chmod 02770 {} \;
server$ exit
local$ git remote add origin ssh://server/opt/git/our_app.git
local$ git push --mirror

A fresh clone of the remote repository showed that everything was available:

local$ git clone ssh://server/opt/git/our_app.git
local$ cd our_app
local$ git branch -a
* master
  remotes/origin/master
  remotes/origin/pre-svn-move
  remotes/origin/tags/mytag-0.1
  remotes/origin/tags/mytag-0.2
  remotes/origin/trunk
  remotes/origin/mybranch-1
  remotes/origin/mybranch-2

Now a remote branch could be checked out:

local$ git checkout -t origin/mybranch-1
local$ git branch
  master
* mybranch-1

Just to re-iterate: this guide includes hints for remote tag and branch availability, mirroring to a remote repo and re-use of values in svn:ignore. I hadn't found all of these in one guide earlier.

A final note: ebneter's tip about svn2git was also great, since this one actually preserves tags as tags, while git-svn converts them to branches. On the other hand, I couldn't get "git svn create-ignore" to work with svn2git...


If this is intended to be a one-way conversion (never going back to svn) I would strongly suggest using svn2git as it greatly simplifies the whole thing. To do the conversion, you basically do

svn2git <svn repo url> --authors <author names & emails file>
git remote add origin <git bare repo url>
git push --all
git push --tags

... that's really all there is to it.


The only suspicious command I can find in your sequence is the

git config branch.master.remote origin

First, your first local repo (from the git svn fetch) should have branches, not remote branches.

Second, your server repo (which does have the right branches), should be able to be cloned with all its refs, meaning the second local repo should list all the remote branches.

Could you try the git svn fetch without the git config branch.master.remote origin?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜