我一直在考慮在我的Subversion版本庫上做一些歷史重寫,但是Subversion目前並不擅長。一種選擇是轉換爲Git(我收集的東西比這更好),重寫,然後轉換回Subversion。什麼,如果有的話,很可能會在這樣的翻譯中丟失(除了歷史的那些部分是假設迷路)?在Subversion和Git之間往返中丟失了什麼?
以防萬一有人感覺就像提供,我只是切換到Git的好建議,答案是:不,我並不想這樣做,:-)
我用下面的代碼如下。它取決於將$ REPO_SVN AND $ REPO_SVN_CLONE設置爲一組Subversion存儲庫,其中一個具有原始存儲庫和一個(幾乎)空的存儲庫以容納該克隆。 (上Google code article on importing from Git爲基礎):
# Create first git repository, containing all my data
git svn clone $REPO_SVN RepoGitA
# Create a svn repository to hold the end product
# It must hold one revision, according to Google Code
# svn propset svn:git:svn 1 WCSvnOut
# svnadmin create RepoSvnOut
# svn co file://`pwd`/RepoSvnOut WCSvnOut
# echo "placeholder" > WCSvnOut/placeholder.txt
# svn add WCSvnOut/placeholder.txt
# svn ci -m "Initial commit of svn-git-svn roundtrip" WCSvnOut
# Create second git repository, connected to the new svn repo
# git svn clone file://`pwd`/RepoSvnOut RepoGitB
git svn clone $REPO_SVN_CLONE RepoGitB
# FROM NOW ON, WORK HAPPENS IN THE SECOND GIT REPOSITORY
cd RepoGitB
# Fetch all the data from the first git repository
git fetch ../RepoGitA
# Create a temporary branch for the fetched repository, and tag its head
git branch tmp $(cut -b-40 .git/FETCH_HEAD)
git tag -a -m "Last fetch" last tmp
# Apply initial commit
# Unfortunately, Git treats the initial commit specially,
# and in particular, cannot rebase it. Work around this as follows:
INIT_COMMIT=$(git log tmp --pretty=format:%H | tail -1)
git checkout $INIT_COMMIT .
git commit -C $INIT_COMMIT
# Rebase:
# Apply all the other commits to the temporary branch,
# and make it the new master branch:
git rebase master tmp
git branch -M tmp master
# Here I could do some more work to rewrite the repo history
# Lastly, commit the changes to the fresh svn repo
git svn dcommit
我的簡單問題是:爲什麼要重寫歷史? – khmarbaise 2011-03-02 14:38:42
主要用於空間原因:我有一些不需要的大型文件的詳細中間歷史記錄。所以我想清除一些中間提交。 – Magnus 2011-03-02 15:27:23