2017-05-19 179 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"