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

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

This question already has an answer here:

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 post 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   bob = Bob Hope  eve = Eve Leave 

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

回答1:

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  --authors  git remote add origin  git push --all git push --tags 

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



回答2:

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?



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!