将 git 项目导入到 Subversion 存储库的子目录中,同时维护历史记录
是否有一种首选方法可以获取 git 存储库并将其作为新的(任意深度嵌套)目录导入现有的 Subversion 存储库,同时维护提交历史记录?
例如,如果我有一个具有以下(简化)目录结构的 subversion 存储库:
backends
backends/A
backends/B
并且我一直在 git 存储库中开发新的后端 C,我现在想要将 git 存储库的内容添加到 svn 存储库中,如下所示后端/C
。
我发现的大多数信息似乎都集中在顶层导入(通常是新创建的或空的 svn 存储库)。
我当前的方法是使用 git-filter-branch 手册页中的以下代码片段将 git 存储库的现有顶层推送到 backends/C
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
然后使用 git svn 和 git rebase 获取将文件放入 svn 存储库中。这是大多数人会这样做的方式,还是有“更好”的方式?
Is there a preferred way to take a git repository and import it into an existing Subversion repository as a new (arbitrarily-deeply-nested) directory while maintaining the commit history?
For example, if I have a subversion repo with the following (simplified) directory structure:
backends
backends/A
backends/B
and I've been working on a new backend C in a git repo, I now want to add the contents of the git repo to the svn repo as backends/C
.
Most information I've found seems to focus on importing at the top-level (generally to a newly created or otherwise empty svn repo).
My current approach is to use the following snippet from the git-filter-branch man page to push the existing top-level of the git repo down to backends/C
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
then use git svn and git rebase to get the files into the svn repo. Is this how most people would do it, or is there a "better" way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望将所有 git 存储库提交到 svn 子目录中,并且不关心 svn 存储库的其余部分未显示在 git 中,则可以将 git-svn 指向该 svn 子目录而不是主目录。
假设您作为示例给出的简化目录结构实际上全部在 trunk/ 中,那么在设置 git-svn 时,您将执行类似 git svn init -Ttrunk/backends/C url 或
的操作git svn init --prefix=backends/C/ url
。这些不是确切的命令,因此请务必参阅文档,但我希望这可以帮助您入门。If you want all of the git repo to be commited into the svn subdir and dont care about the rest of the svn repo not showing up in git, you can just point git-svn at that svn subdir instead of the main dir.
Assuming the simplified directory structure you gave as an example is actually all in trunk/, then when setting up git-svn you would do something like
git svn init -Ttrunk/backends/C url
orgit svn init --prefix=backends/C/ url
. These arent exact commands so be sure to refer to the documentation but I hope this gets you started.