如何git克隆所有分支都位于根目录下的SVN存储库? [英] How to git clone an SVN repository where all branches are located in root?
问题描述
我的SVN结构是这样的:
/
|-Branch1
|- Branch2
|-Branch3
...
我该如何克隆它
奖金问题:如何仅将SVN分支的一个子集克隆到新的git仓库中?
p>
我相信SVN中的分支只是文件夹,这只是一个约定。 Git实际上与分支一起工作。有了这种方法,就变得更容易了。
由于需要从SVN存储库中获取数据,因此需要为其创建远程目录。从结构中,我看到您需要在git存储库中创建分支1至3。
创建Git存储库。
git init
git config --local --add user.name< Username>
git config --local --add user.email< email>
echo MASTER> master
git add master
git commit -m虚拟提交
创建
git config --add svn-remote。< BranchName> .url< SVN URL> < BranchName> .fetch:refs / remotes /< RemoteName>
git config --add svn-remote。
Branch1:
git config --add svn-remote.branch1.url https:// svnhost / svn / MyRepo / Branch1
git config --add svn-remote.branch1.fetch:refs / remotes / branch1_remote
获取branch1的SVN数据:
git svn fetch branch1
为其他两个分支重复此操作和Branch3。
如果您只是尝试克隆,则可以在此处停止。除非您要使用Git存储库,否则无需进一步操作。 Google在git子树上知道为什么这可能是正确的解决方案。
要创建子树:
查找上一个提交ID:
git checkout remotes / branch1_remote
git svn log -n 1 --show-commit --oneline
输出:734713bc047d87bf7eac9674765ae793478c50d3(This是您的LastCommitId值)
在主线主分支中创建子树:
git checkout master
git子树add --prefix = Branch1< LastCommitId>
对您来说,奖金问题:试试这个
git svn clone https:// svnhost / svn / MyRepo / Branch2
这很简单,另一种方法是按照上述步骤操作,而不是在同一存储库中创建三个远程服务器,而不是每次都创建新的存储库,然后添加分支的远程服务器。根据您的要求,您可以用其他方式搜索Google。
My SVN structure is like this:
/
|-- Branch1
|-- Branch2
|-- Branch3
...
How can I clone this into a git repository preserving the branches (i.e. not flat history)?
Bonus question: How to clone only a subset of the SVN branches into a new git repository?
I believe that in SVN branches are just folders, its just a convention. Git actually works with branches. With this the approach becomes easier.
As you need to fetch the data from SVN repository you will need to create remote for it. From the structure I see that you need to create Branch 1 to 3 in your git repository.
Create Git repository.
git init
git config --local --add user.name <Username>
git config --local --add user.email <email>
echo "MASTER" > master
git add master
git commit -m "Dummy commit"
Create Remote of your SVN branch.
git config --add svn-remote.<BranchName>.url <SVN URL>
git config --add svn-remote.<BranchName>.fetch :refs/remotes/<RemoteName>
for Branch1:
git config --add svn-remote.branch1.url https://svnhost/svn/MyRepo/Branch1
git config --add svn-remote.branch1.fetch :refs/remotes/branch1_remote
Fetch SVN data of branch1:
git svn fetch branch1
Repeat this for other two branches Branch2 and Branch3.
You can stop right here if you are only trying to clone You need not proceed further unless you want to work with Git repository. Google on git subtree to know why this could be correct solution in your case.
To Create Subtree:
Find last commit id:
git checkout remotes/branch1_remote
git svn log -n 1 --show-commit --oneline
Output: 734713bc047d87bf7eac9674765ae793478c50d3 (This is yout LastCommitId value)
Create subtree in mainline master branch:
git checkout master
git subtree add --prefix=Branch1 <LastCommitId>
For you bonus question: Try this
git svn clone https://svnhost/svn/MyRepo/Branch2
This one is simple, the other way is to follow the above steps and instead of creating three remotes in same repository create new repository everytime and then add your branch's remote. Based on your requirement you could google out different ways.
这篇关于如何git克隆所有分支都位于根目录下的SVN存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!