如何用git-svn迁移SVN多分支至本地Git仓库并保留分支结构?
SVN分支迁移至Git的配置问题
背景信息
SVN仓库目录结构
https://hogehoge/svn/ trunk/ hoge/ release01/ release02/ tags/ hoge/ branches/ project1/src project2/src
预期本地Git仓库结构
c:\Sample\sampleForGit branches/ project1/src project2/src
当前配置及问题
已配置.git/config如下,但未达到预期效果:
[svn-remote "svn"] url = https://hogehoge/svn/ fetch = branches/project1:refs/remotes/git-svn/branches/project1 fetch = branches/project2:refs/remotes/git-svn/branches/project2 branches = branches/project1/*:refs/remotes/git-svn/branches/project1/* branches = branches/project2/*:refs/remotes/git-svn/branches/project2/*
当前本地仓库分支未区分,结构变为:
c:\Sample\sampleForGit branches/ src
解决方案
问题出在branches配置的通配符*上——它匹配了project1/和project2/下的src目录,导致Git把src当成了分支名,而非保留project1和project2作为独立分支。
修改配置为以下内容即可:
[svn-remote "svn"] url = https://hogehoge/svn/ # 直接将project1和project2作为独立的远程分支根 fetch = branches/project1:refs/remotes/git-svn/project1 fetch = branches/project2:refs/remotes/git-svn/project2
配置完成后,执行以下步骤重新同步:
- 清理现有错误的远程分支引用:
git svn reset -r 0
- 重新拉取SVN分支:
git svn fetch
- 将远程分支转为本地分支:
git checkout -b project1 git-svn/project1 git checkout -b project2 git-svn/project2
这样本地仓库就会生成project1和project2两个独立分支,每个分支下保留原SVN中的src目录结构,符合预期需求。
内容的提问来源于stack exchange,提问作者kagecafe
相关产品推荐
相关产品推荐

