如何在SVN迁移到Git后列出并获取远程分支?
我将我们的SVN存储库迁移到Git并将其推送到中央存储库。我们有相当多的标签和分支,但不知何故,我们无法列出并从Git客户端获取这些内容。这很奇怪,因为标签和分支似乎在服务器上可用。如何在SVN迁移到Git后列出并获取远程分支?
在Jon Maddox blog post的帮助下,blog post from Marc Liyanage和SO answer from Casey我能够将解决方案缝合在一起。感谢所有的帮助!
这是我最终做的。首先,我创建与SVN的提交文件:
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 <[email protected]>
bob = Bob Hope <[email protected]>
eve = Eve Leave <[email protected]>
然后,我创建了一个混帐回购协议从我们的SVN回购:
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
这最后一步是至关重要的,否则分支/标签是不可用时从远程存储库克隆。不管怎样,我把这个给一个新的远程回购:
远程储存的新鲜克隆表明,一切都可用:
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
现在的远程分支可以签出:
local$ git checkout -t origin/mybranch-1
local$ git branch
master
* mybranch-1
只是重新迭代:本指南包含远程标记和分支可用性的提示,镜像到远程repo以及在svn:ignore中重用值。我以前没有在一个指南中找到所有这些。
最后一点:ebneter's tip about svn2git也很棒,因为它实际上将标签保留为标签,而git-svn将它们转换为分支。在另一方面,我不能让“混帐SVN创建,忽略”与svn2git工作...
唯一可疑的命令,我可以在你的序列发现是
git config branch.master.remote origin
首先,你的第一本地回购(从git svn fetch
)应该有分支机构,而不是远程分支机构。
其次,你的服务器回购(它的确有正确的分支)应该能够被所有的引用克隆,这意味着第二个本地回购应该列出所有的远程分支。
您可以试试git svn fetch
没有git config branch.master.remote origin
?
如果这是一个单向转换(永远不会回到svn),我强烈建议使用svn2git,因为它大大简化了整个事情。要做转换,你基本上可以做
svn2git <svn repo url> --authors <author names & emails file>
git remote add origin <git bare repo url>
git push --all
git push --tags
......这就是它的全部。
ebneter:是的,我在昨天看到你的答案之前尝试了nirvdrum的svn2git(有几个!),它的功能就像一个魅力!它甚至正确地做了标签,而git-svn没有。现在唯一的问题是以前的文件夹移动没有正确注册:当我将branch1/content分支到branch2/moved_here/content时,它会比较根文件夹... – neu242 2010-10-26 06:29:49
这些是在转换之前完成的移动?或之后? – ebneter 2010-10-26 06:48:04
不幸的是,这不会推动分支,因为svn2git将所有分支放在远程/ ****下 – willCode4Beer 2011-04-20 07:14:36
在“git-svn fetch”之后,分支显示为远离开始。 “git config branch.master.remote origin”似乎没有任何影响,我已经尝试了没有它的整个序列。 – neu242 2010-10-25 10:47:30
@ neu242:有趣。我不明白的是,为什么分支在你的push镜像之后被列在服务器repo中。无论如何,对于第一个本地回购,请尝试跟踪所有远程分支,然后再推送到您的裸回购:http://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches – VonC 2010-10-25 10:50:33
确定,我在最初推送之前为所有分支做了“git branch --track”。现在所有分支/标签都被列为类似于“遥控器/标签/ mytag-0.1”和“标签/ mytag-0.1”。然后我做了一个“git push --mirror”。所有标签和分支现在在服务器上列出两次(没有远程/ *)。但在客户端上新建一个“git clone ssh://server/opt/git/our_app.git”后,“git branch -r”会列出所有标签/分支(不是两次)。所以这很好。我应该担心这些骗局吗? – neu242 2010-10-25 11:58:43