在Subversion和Git之间的往返中丢失了什么?

时间:2011-03-02 14:32:54

标签: svn git

我一直在考虑在我的Subversion存储库上做一些历史重写,但Subversion目前还不是很擅长。一种选择是转换为Git(我收集的那种东西要好得多),重写,然后转换回Subversion。什么,如果有的话,可能会在这样的翻译中迷失(除了所谓迷失的历史部分之外)?

如果有人想提出我刚刚转到Git的建议,答案是:不,我不想这样做: - )

我使用的代码如下。这取决于将$ REPO_SVN和$ 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

1 个答案:

答案 0 :(得分:-1)

这听起来不是一个好主意。在git中,您应该只重写尚未发布的历史记录。在subversion和其他客户端 - 服务器SCM中,所有历史记录已发布到中央服务器,因此 no 历史记录可以安全地重写。

为什么要重写历史记录?你想要实现什么目标?