SVN 到 Git 迁移后如何列出和获取远程分支? [英] How do I list and fetch remote branches after SVN to Git migration?
问题描述
我将我们的 SVN 存储库迁移到 Git 并将其推送到中央存储库.我们有相当多的标签和分支,但不知何故,我们无法从 Git 客户端列出和获取它们.这很奇怪,因为标签和分支似乎在服务器上可用.
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.
在 Jon Maddox 博客文章,Marc Liyanage 的博文 和 凯西的回答 我能够将解决方案拼接在一起.感谢大家的帮助!
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!
这就是我最终要做的.首先,我使用 svn 提交者创建了一个文件:
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>
然后我从我们的 svn 存储库创建了一个 git 存储库:
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
只是重申一下:本指南包括远程标签和分支可用性的提示,镜像到远程仓库和重用 svn:ignore 中的值.我之前没有在一本指南中找到所有这些内容.
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.
最后一点:ebneter 关于 svn2git 的提示 也很棒,因为这个实际上将标签保留为标签,而 git-svn 将它们转换为分支.另一方面,我无法让git svn create-ignore"与 svn2git 一起工作......
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...
推荐答案
如果这是一种单向转换(永远不会回到 svn),我强烈建议使用 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.
这篇关于SVN 到 Git 迁移后如何列出和获取远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!