[英]How to convert to GIT an old SVN repository with trunk/branches created later
I'm trying to migrate a really old SVN repository to GIT maintaining history, but having in mind that the repository didn't have the trunk/branches/tags structure all the time, but instead it was created without them, and the repository was migrated to the trunk/branches/tags structure later.我正在尝试将一个非常旧的 SVN 存储库迁移到 GIT 维护历史记录,但请记住,存储库并不是一直都有主干/分支/标签结构,而是在没有它们的情况下创建的,并且存储库是稍后迁移到主干/分支/标签结构。
I've tried with git-svn with the command:我已经尝试使用 git-svn 使用以下命令:
git svn clone <repo_url> --stdlayout
but the problem is that history gets cut on the "trunk, branches and tags created" commit, so everything before that commit is lost.但问题是历史在“创建的主干、分支和标签”提交时被删除,因此在该提交之前的所有内容都丢失了。 I've also tried with:
我也尝试过:
git svn clone <repo_url> -T/ -bbranches -ttags
which gets all the commits, but creates a real mesh in the commit graph because it duplicates commits in the branches and the trunk, and does not create any relation between master and branches.它获取所有提交,但在提交图中创建了一个真实的网格,因为它复制了分支和主干中的提交,并且不会在主分支和分支之间创建任何关系。 I tried cleaning it up with commands like:
我尝试使用以下命令对其进行清理:
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch branches tags" -- --all
which removes the branches folder form the trunk branch mostly right, (and removes a lot of duplicated commits) and also trying to move the trunk folder to the root with:它从主干分支中删除了分支文件夹,大部分是正确的,(并删除了许多重复的提交)并且还尝试将主干文件夹移动到根目录:
git filter-branch --tree-filter "if test -d 'trunk'; then git mv trunk/\* .; fi" --tag-name-filter cat --prune-empty -- --all
but doesn't work.但不起作用。 I'm working on windows, so the command in git-svn docs for moving all items is not working for me (missing sed):
我正在使用 Windows,因此 git-svn 文档中用于移动所有项目的命令对我不起作用(缺少 sed):
git filter-branch --index-filter \
'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
(which I rewrote to :) (我重写为:)
git filter-branch --index-filter \
'git ls-files -s | sed "s-\t\"trunk/\(*\)-\1-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
Any idea if what I'm trying to do is possible or should I just quit and keep history only until creation of trunk/branches/tags?知道我正在尝试做的事情是否可行,还是应该退出并仅保留历史记录,直到创建主干/分支/标签?
I finally found a solution: using svn-all-fast-export (svn2git) I got to create a repository with all the history with the following script:我终于找到了一个解决方案:使用 svn-all-fast-export (svn2git) 我必须使用以下脚本创建一个包含所有历史记录的存储库:
create repository REPONAME
end repository
# Master branch
match /
repository REPONAME
max revision REVISION_BEFORE_TRUNK_BRANCHES_TAGS_CREATION
branch master
end match
match /trunk/
repository REPONAME
branch master
end match
# Common branches
match /branches/([^/]+)/
repository REPONAME
branch \1
end match
# Ignore everything else
match /
end match
As I was on windows, had to compile on Windows Substime for Linux, installing "build-essential subversion git qtchooser qt5-default libapr1 libapr1-dev libsvn-dev";当我在 Windows 上时,必须在 Windows Substime for Linux 上编译,安装“build-essential subversion git qtchooser qt5-default libapr1 libapr1-dev libsvn-dev”; or cygwin with the following libs (as explained in this issue )
或带有以下库的 cygwin(如本期所述)
gcc-g++ (v7.4.0-1)
libQt5Core-devel (v5.9.4-2)
libapr1 (v1.6.5-1)
libapr1-devel (v1.6.5-1)
make (v4.2.1-2)
subversion (v1.11.1-1)
subversion-devel (v1.11.1-1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.