我將我們的SVN存儲庫遷移到Git並將其推送到中央存儲庫。我們有相當多的標籤和分支,但不知何故,我們無法列出並從Git客戶端獲取這些內容。這很奇怪,因爲標籤和分支似乎在服務器上可用。如何在SVN遷移到Git後列出並獲取遠程分支?
在Jon Maddox blog post的幫助下,blog post from Marc Liyanage和SO answer from Casey我能夠將解決方案縫合在一起。感謝所有的幫助!
這是我最終做的。首先,我創建與SVN的提交文件:
local$ svn log svn://server/opt/svn/our_app |grep ^r[0-9] | cut -f2 -d\| |sort |uniq | tee ~/users.txt
alice
bob
eve
local$ vim ~/users.txt
local$ cat ~/users.txt
alice = Alice Malice <[email protected]>
bob = Bob Hope <[email protected]>
eve = Eve Leave <[email protected]>
然後,我創建了一個混帳回購協議從我們的SVN回購:
local$ mkdir our_app
local$ cd our_app
local$ git svn init --stdlayout svn://server/opt/svn/our_app
local$ git config svn.authorsfile ~/users.txt
local$ git svn fetch
local$ git svn create-ignore
local$ git commit -m 'added .gitignore, created from svn:ignore'
local$ for remote in `git branch -r`; do git checkout -b $remote $remote; done
這最後一步是至關重要的,否則分支/標籤是不可用時從遠程存儲庫克隆。不管怎樣,我把這個給一個新的遠程回購:
遠程儲存的新鮮克隆表明,一切都可用:
local$ git clone ssh://server/opt/git/our_app.git
local$ cd our_app
local$ git branch -a
* master
remotes/origin/master
remotes/origin/pre-svn-move
remotes/origin/tags/mytag-0.1
remotes/origin/tags/mytag-0.2
remotes/origin/trunk
remotes/origin/mybranch-1
remotes/origin/mybranch-2
現在的遠程分支可以簽出:
local$ git checkout -t origin/mybranch-1
local$ git branch
master
* mybranch-1
只是重新迭代:本指南包含遠程標記和分支可用性的提示,鏡像到遠程repo以及在svn:ignore中重用值。我以前沒有在一個指南中找到所有這些。
最後一點:ebneter's tip about svn2git也很棒,因爲它實際上將標籤保留爲標籤,而git-svn將它們轉換爲分支。在另一方面,我不能讓「混帳SVN創建,忽略」與svn2git工作...
在「git-svn fetch」之後,分支顯示爲遠離開始。 「git config branch.master.remote origin」似乎沒有任何影響,我已經嘗試了沒有它的整個序列。 – neu242 2010-10-25 10:47:30
@ neu242:有趣。我不明白的是,爲什麼分支在你的push鏡像之後被列在服務器repo中。無論如何,對於第一個本地回購,請嘗試跟蹤所有遠程分支,然後再推送到您的裸回購:http://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches – VonC 2010-10-25 10:50:33
確定,我在最初推送之前爲所有分支做了「git branch --track」。現在所有分支/標籤都被列爲類似於「遙控器/標籤/ mytag-0.1」和「標籤/ mytag-0.1」。然後我做了一個「git push --mirror」。所有標籤和分支現在在服務器上列出兩次(沒有遠程/ *)。但在客戶端上新建一個「git clone ssh://server/opt/git/our_app.git」後,「git branch -r」會列出所有標籤/分支(不是兩次)。所以這很好。我應該擔心這些騙局嗎? – neu242 2010-10-25 11:58:43