團隊從 SVN 遷移至 Git 過渡期,或需同時支援兩套版控,可用 git svn 雙向同步。本文說明建立作者映射、克隆 SVN trunk、同步提交的核心流程。
所有 Subversion 橋接操作皆以 git svn 開頭。
SVN 用帳號,Git 用「姓名 <email>」。先匯出所有提交者:
svn log --xml | grep "^" | sort -u | \
awk -F'' '{print $2}' | awk -F' ' '{print $1}' > users.txt
編輯 users.txt 格式:
schacon = Scott Chacon
selse = Someo Nelse
git svn clone https://example.com/path/to/project-x/trunk \
--authors-file=users.txt project-x
--authors-file:指定映射檔,讓 Git 提交作者資訊正確。project-x:本地目錄名。--no-metadata 不保留 SVN 中繼資料,體積較小。**共用模式請勿加**。# 從 SVN 更新到 Git
git svn rebase
# 將 Git 本地提交推送到 SVN
git svn dcommit
# 查看 SVN 分支
git svn branch -l
# 建立對應 SVN 分支的 Git 分支
git checkout -b feature-x remotes/origin/feature-x
git svn **不支援 Git 合併提交 (merge commit)**,推送到 SVN 會被線性化 (rebase),避免在 Git 做複雜合併再 dcommit。git svn clone -r HEAD 只取最新版再補歷史。--tags 參數。