SVN倉庫遷移到Git的完美解決辦法


參考文章Converting a Subversion repository to Git

1 使用git svn clone 拷貝svn倉庫

cd ~/test_repo
git svn clone file:///home/***/Desktop/SVN/svn_repo/ -T trunk -b branches -t tags

2 新建一個git的bare倉庫

cd ..
mkdir test.git
cd test.git
git init --bare

3 將git的默認分支和svn的默認分支trunk對應起來

git symbolic-ref HEAD refs/heads/trunk

4 將test_repo推送到test.git中

cd ~/test_repo
git remote add bare ~/test.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare

此時就完成了推送,可以刪除test_repo了

5 將git repo中的trunk重命名為master

cd ~/test.git
git branch -m trunk master

6 將svn repo中的tags移動到git repo的相應位置

使用git svn clone導出版本庫的時候會將svn中的tags保存成git中的tags/**,而並不是默認的tag,所以要進行移動

cd ~/test.git
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done

7 完成遷移,得到test.git

進入工作文件夾,執行

git clone ~/test.git

使用git進行版本管理吧


轉載請聯系chasenwu@live.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM