我一直在用Git做我所有的工作,并将其推送到GitHub。我对软件和网站都很满意,我不希望在这一点上改变我的工作实践。

我的博士导师要求所有学生将作业保存在学校托管的SVN存储库中。我发现了大量关于将现有的SVN存储库下拉到Git中的文档和教程,但没有关于将Git存储库推到新的SVN存储库中的文档和教程。我希望通过结合Git -svn、一个新的分支和rebase以及所有这些美妙的术语来实现这一点,但我是Git新手,对其中任何一个都没有信心。

然后,当我选择时,我希望只运行几个命令将提交推到SVN存储库。我希望继续使用Git,让SVN存储库镜像Git中的内容。

我将是唯一一个致力于SVN的人,如果这有什么不同的话。


当前回答

您可以创建一个新的SVN存储库。导出您的Git项目(充实. Git文件)。将其添加到SVN存储库中(使用Git中现有的内容初始化存储库)。 然后使用在新的Git项目中导入SVN存储库的说明。

但是这会丢失之前的Git历史记录。

其他回答

我只是想分享一些我的经验和公认的答案。我做了所有的步骤,在我运行最后一步之前,一切都很好:

git svn dcommit

$ git SVN dcommit 使用未初始化的值$u替换/usr/lib/perl5/vendor_perl/5.22/Git/SVN。下午101线。 在/usr/lib/perl5/vendor_perl/5.22/Git/SVN中使用未初始化的值$u(.)或字符串。下午101线。 refs/remotes/origin/HEAD:“https://192.168.2.101/svn/PROJECT_NAME”中没有找到

我找到了线程https://github.com/nirvdrum/svn2git/issues/50,最后我在101行下面的文件中应用了解决方案 /usr/lib/perl5/vendor_perl / 5.22 / Git / SVN.pm

我更换了

$u =~ s!^\Q$url\E(/|$)!! or die

with

if (!$u) {
    $u = $pathname;
} 
else {
       $u =~ s!^\Q$url\E(/|$)!! or die
      "$refname: '$url' not found in '$u'\n";
}

这解决了我的问题。

我建议使用SubGit用4个命令编写一个非常短的指令。详情请看这篇文章。

在我的例子中,我必须从SVN启动一个干净的项目

$ Project> git svn init protocol://path/to/repo -s
$ Project> git svn fetch

添加你所有的项目资源…

$ Project> git add .
$ Project> git commit -m "Importing project sources"
$ Project> git svn dcommit

有三种方法:

Rebase:与其他答案相同 提交id:查找SVN的第一个提交id和git的第一个提交id,将它们回显到。git/info/grafts:echo "git_id svn_id}" > .git/info/grafts then git SVN dcommit 检查每一个git提交,复制文件到svn_repo, SVN提交

bash演示: github演示

v1。X:使用rebase和commit id

v2。X:使用复制文件,然后SVN提交

这就是我要做的。假设我的本地分支名为main。填补空白,因为我不记得确切的git svn命令,因为我已经有一段时间没有使用它了。

create in svn the branch that will be used for the project. use git svn to clone the svn repo you want (at least, the branch you want to use so that you do not have to fetch the other millions of revisions that we do not care about for this endeavor). checkout the svn branch in the new git repo. Add to this repository a remote that points to the original git repo you are using for the project. Let's say the remote is called the-real-stuff. git fetch the-real-stuff # so that we get to see what's in the real repo Given that this is the first time we will be pulling our code into the svn one, we have to trick git so that it can "merge" that code: git merge --allow-unrelated-histories the-real-stuff/main -m "Whatever comment I want in the svn revision". This will "merge" both branches locally. git svn dcommit so that you can push the content of the project as it is right now.

继续工作在原来的git回购。然后,当你想要推入svn时,去到git的svn clone,然后做:

git fetch the-real-stuff # get visibility to the changes in the original git repo
git merge the-real-stuff/main -m "Whatever comment I want to show on this svn revision"
git svn dcommit

这样就做完了。

我喜欢使用2个回购的想法,这样我们就不用用svn的东西来填充原始的回购,尽管有可能将整个东西保留在一个git回购中。