使用 Git-SVN 从 SVN 迁移到 git

Migration from SVN to git using Git-SVN

我正在尝试使用 Git-SVN 将存储库从 SVN 迁移到 git。问题是我只想迁移主干中的一些文件夹但没有分支也没有标签。我正在使用 "git svn fetch" 命令首先获取我要迁移的文件。我的 SVN 存储库是这样的:

https://svn.myexamplerepo.com/

trunk/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 或有时什么都没有。我做错了什么或者有更好的方法吗?我看过其他一些问题,但 none 似乎清楚地回答了这个问题。

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

1.Clone 文件夹A

# 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

我找到了一种通过添加 --include-paths 或 --ignore-paths 来实现这一点的方法。因此,例如使用--include-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

使用 --ignore-paths 时列出您不想克隆的路径。

所以要使用 svn 进行克隆 git 克隆:

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