2017-05-19 181 views
-2

我正尝试使用Git-SVN从SVN迁移到git。问题是我只想迁移干线中的一些文件夹,但没有分支和标签。我使用“git svn fetch”命令首先获取我想要迁移的文件。我的SVN仓库是这样的:使用Git-SVN从SVN迁移到git

https://svn.myexamplerepo.com/

主干/ MyProject的/

|-FolderA 
|-FolderB 
    |-SubFolderB1 
    |-SubFolderB2 
    |-SubSubFolderB2X 
    |-SubSubFolderB2Y 
    |-SubFolder3 
|-FolderC  
|-File1.txt 
|-File2.txt 

我只是想获取

trunk/MyProject/FolderA 
trunk/MyProject/FolderB/SubFolderB2/SubSubFolderB2Y 
trunk/MyProject/File1.txt 

,但我有一个很难搞清楚如何去做这个。我试图修改我的git配置文件到:

[core] 
    repositoryformatversion = 0 
    filemode = false 
    bare = false 
    logallrefupdates = true 
    symlinks = false 
    ignorecase = true 
[svn-remote "FolderA"] 
    url = https://svn.myexamplerepo.com/ 
    fetch = trunk/FolderA:refs/remotes/origin/FolderA 
[svn-remote "SubFolderB2Y"] 
    url = https://svn.myexamplerepo.com/ 
    fetch =trunk/FolderB/SubFolderB2/SubSubFolderB2Y:refs/remotes/origin/SubFolderB2Y 
[svn-remote "File1"] 
    url = https://svn.myexamplerepo.com/ 
    fetch = trunk/File1.txt:refs/remotes/origin/File1 
[svn] 
    authorsfile = C:/MyMigration/authors.txt 

但这不起作用。我只得到File1.txt,或者根本没有。我做错了什么或者有没有更好的方法来做到这一点?我看过其他一些问题,但没有一个能够清楚地回答这个问题。

回答

1

更改.git/config文件无法达到目标。您可以分别使用git svn clone将不同的文件夹/文件克隆到git存储库中,然后将git存储库组合在一起。如下面详细步骤:

1.Clone FolderA

# In a directory (such as d:\repos) 
git svn clone https://svn.myexamplerepo.com/trunk/MyProject/FolderA 
cd FolderA 
mkdir FolderA 
mv * FolderA 
git add . 
git commit -m 'move to FolderA' 

2.Clone SubSubFolderB2Y

# In a directory (such as d:\repos) 
git svn clone https://svn.myexamplerepo.com/trunk/MyProject/FolderB/SubFolderB2/SubSubFolderB2Y 
cd SubSubFolderB2Y 
mkdir SubSubFolderB2Y 
mv * SubSubFolderB2Y 
git add . 
git commit -m 'move to SubSubFolderB2Y' 

3.Clone FILE1.TXT

# In a directory (such as d:\repos) 
git svn clone https://svn.myexamplerepo.com/trunk/MyProject 
cd MyProject 
#delete all the files and folder except File1.txt 
git commit -am 'keep File1.txt' 

4.Combine所有的Git仓库一起

# in FolderA directory (d:\repos\FolderA) 
git remote add subB d:/repos/SubSubFolderB2Y 
git remote add file d:/repos/MyProject 
git pull subB master --allow-unrelated-histories 
git pull file master --allow-unrelated-histories 

现在d:\repos\FolderA git的回购是你想要的,它包含:

FolderA 
SubSubFolderB2Y 
File1.txt 
+0

混帐SVN的init +混帐SVN获取相同的git svn的克隆。是的,我也可以使用git svn clone和--trunck = ...来克隆我的没有分支或标签的回购,但没有--branches和--tags,但这无助于克隆trunck中的特定文件夹。 – CPL

+0

好吧,既然你想使用git -svn,我就用git-svn的方式更新了我的答案。你可以试试。 –

+0

谢谢,这种方法的作品,所以我会给你信贷的答案。不过,我想出了一个更简单的方法来做我需要的。 – CPL

0

我想通了,加入这样的方式--include-paths或--ignore-paths。因此,例如使用 - 包括路径:

[core] 
    repositoryformatversion = 0 
    filemode = false 
    bare = false 
    logallrefupdates = true 
    symlinks = false 
    ignorecase = true 
[svn-remote "svn"] 
    include-paths = FolderA|FolderB/SubFolderB2/SubSubFolderB2Y|File1.txt 
    url = https://svn.myexamplerepo.com/ 
    fetch = MyProject:refs/remotes/trunk 
[svn] 
    authorsfile = C:/MyMigration/authors.txt 

当使用 - 忽略路径,然后列出你不希望克隆的路径。

所以使用SVN混帐克隆做一个克隆:

git svn clone --trunk="/FolderA" --include-paths="FolderA|FolderB/SubFolderB2/SubSubFolderB2Y|File1.txt" --authors-file=authors.txt "https://svn.myexamplerepo.com/" "./MyGitFolder"