如何将 svn 分支和标签导入 git-svn? [英] How to import svn branches and tags into git-svn?
问题描述
我有一个必须提交的中央 SVN 存储库,但我对 git 充满热情(就像我认识的任何其他开发人员一样).这个案子是众所周知的.
I have got a central SVN repository I must commit to, but I've got a passion for git (like any other developer I know). The case is well known.
然后我阅读了 git-svn 并尝试了一下.由于我不需要完整的历史记录,只需两个月左右,我就这样做了:
Then I read about git-svn and gave it a try. Since I don't need the full history, just from two months or so, I did like this:
git svn clone -r 34000 -s https://svn.ourdomain.com/svn/repos/Project/SubProject
SubProject 像往常一样有子目录 trunk
、tags
和 branches
.太好了.
SubProject had, as usual, the subdirectories trunk
, tags
and branches
. Great.
然后,为了得到最后的修订版,我做到了
Then, in order to get the last revision, I did
git svn rebase
稍后下载一些,很棒.上次修订、日志等.好的,现在我将切换到我的功能分支.
Some downloads later, great. Last revision, logs, etc. Ok, now I'll switch to my feature branch.
$ git branch
* master
$ git branch -r
trunk
$ git branch -a
* master
remotes/trunk
问题是:我的分支机构在哪里?我做错了什么吗?我应该怎么做才能在新的 git repo 中获取我的分支?
The questions are: Where are my branches? Have I done something wrong? How should I do in order to get my branches in the new git repo?
git-svn,无论我在哪里读到过它,都明智地处理了分支和标签,但行为并不是我所期望的.谢谢!
git-svn, wherever I have read about it, dealt wisely with branches and tags, but the behaviour is not what I expected. Thanks!
编辑:我刚刚发现 git svn fetch
可以做到.但它会得到所有的修改,这是我不喜欢的.
EDIT: I have just found out that git svn fetch
will do it. But it will get all revisions, which is something I wouldn't like.
推荐答案
您需要几个步骤.
提供正确的主干、分支和标签文件夹名称并获取 svn repo:
supply proper trunk, branches and tags folder names and fetch svn repo:
git svn init -t tags -b branches -T trunk https://mysvn.com/svnrepo
git svn fetch
由于 svn 中的标签是真正的分支,所以从标签分支创建 git 标签:
Since tags in svn are real branches, create git tags from tag branches:
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags | cut -d / -f 3- |
while read ref
do
echo git tag -a $ref -m 'import tag from svn'
done
删除标签分支
Delete tag branches
git for-each-ref --format="%(refname:short)" refs/remotes/tags | cut -d / -f 2- |
while read ref
do
echo git branch -rd $ref
done
由于在上一步中标记的标签指向提交创建标签",我们需要派生真实"标签,即创建标签"提交的父项.
Since tags marked in the previous step point to a commit "create tag", we need to derive "real" tags, i.e. parents of "create tag" commits.
git for-each-ref --format="%(refname:short)" refs/tags |
while read ref
do
tag=`echo $ref | sed 's/_/./g'` # give tags a new name
echo $ref -> $tag
git tag -a $tag `git rev-list -2 $ref | tail -1` -m "proper svn tag"
done
我们现在要做的就是删除旧标签.
All we have to do now is to remove old tags.
这篇关于如何将 svn 分支和标签导入 git-svn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!