git svn clone specific branches and merge

不羁岁月 提交于 2021-02-17 05:27:10

问题


I am looking to migrate my codebase from svn to git. There are too many branches in my svn repo. I only wish to clone couple of branches and merge them together and push it to git. I want to avoid cloning all branches as it takes long time. How do I achieve this?

After it's done, I want to periodically get update from those svn branches, merge them and update the git repo and the svn will be active for certain period of time. It would be waste of time if I have to clone it again. Is there a way to do what I require?


回答1:


I think SubGit tool might be the best solution for your case:

https://subgit.com

It allows translating data from SVN to Git including and excluding any branches/tags or even directories inside, so it's easy to get only those branches you want to have in Git. Say, if you have branches 'branch_1'… 'branch_N', but intend to have in Git only 'branch_3' and 'branch_4' (along with 'trunk'), then you can set SubGit as follows:

[svn]

trunk=trunk:/refs/heads/master   
branches=branches/branch_3:/refs/heads/branch_3   
branches=branches/branch_4:/refs/heads/branch_4

and only those branches will appear in Git.

SubGit supports continuous two-way mirror between SVN and Git, so it's perfectly possible not only get updates from SVN, but send those from Git, too. It also possible to only get updates from SVN by running import periodically, yet in this case, branches that came from SVN should not be changed in GIt.




回答2:


git svn fetch (and clone) have --ignore-paths and --include-paths so you can ignore some branches/tags (which are paths in SVN repo) or include only matching branches/tags. So it should be something like

git init from_svn
cd from_svn
git config svn-remote.svn.url "svn://…"
git config svn-remote.svn.include-paths "^/branches/3\." # Include only branches that match name 3.*
git svn fetch svn


来源:https://stackoverflow.com/questions/50746949/git-svn-clone-specific-branches-and-merge

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