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

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

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

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


当前回答

还有一个有效的序列(每个步骤都有一些注释):

Install git-svn and subversion toolkits: sudo apt-get install git-svn subversion Switch inside the PROJECT_FOLDER cd PROJECT_FOLDER Create the project path on the Subversion server (unfortunately the current git-svn plugin has a defect in comparison with TortoiseSVN). It is unable to store source code directly into the PROJECT_FOLDER. Instead, by default, it will upload all the code into PROJECT_FOLDER/trunk. svn mkdir --parents protocol:///path/to/repo/PROJECT_FOLDER/trunk -m "creating git repo placeholder"

在这里,中继在路径的末端是强制性的

Initialize the git-svn plugin context inside the .git folder git svn init -s protocol:///path/to/repo/PROJECT_FOLDER This is the place where trunk at the end of the path is unnecessary Fetch an empty Subversion repository information git svn fetch This step is helping to synchronize the Subversion server with the git-svn plugin. This is the moment when git-svn plugin establishes remotes/origin path and associates it with the trunk subfolder on the server side. Rebase old Git commits happened before the git-svn plugin became involved in the process (this step is optional) git rebase origin/trunk Add new/modified files to commit (this step is regular for Git activities and is optional) git add . Commit freshly added files into the local Git repository (this step is optional and is only applicable if step 7 has been used): git commit -m "Importing Git repository" Pushing all the project changes history into the Subversion server: git svn dcommit

其他回答

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

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

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

> SVN,具有完整的提交历史

我有一个Git项目,必须把它移到SVN上。这是我如何做到的,保持整个提交历史。唯一丢失的是原始提交时间,因为libSVN在执行git svn dcommit时将设置本地时间。

Howto:

Have a SVN repository where we want to import our stuff to and clone it with git-svn: git svn clone https://path.to/svn/repository repo.git-svn` Go there: cd repo.git-svn Add the remote of the Git repository (in this example I'm using C:/Projects/repo.git). You want to push to SVN and give it the name old-git: git remote add old-git file:///C/Projects/repo.git/ Fetch the information from the master branch from the old-git repository to the current repository: git fetch old-git master Checkout the master branch of the old-git remote into a new branch called old in the current repository: git checkout -b old old-git/master` Rebase to put the HEAD on top of old-git/master. This will maintain all your commits. What this does basically is to take all of your work done in Git and put it on top of the work you are accessing from SVN. git rebase master Now go back to your master branch: git checkout master And you can see that you have a clean commit history. This is what you want to push to SVN. Push your work to SVN: git svn dcommit

这是所有。这是非常干净的,没有黑客,一切工作完美的开箱即用。享受。

还有一个有效的序列(每个步骤都有一些注释):

Install git-svn and subversion toolkits: sudo apt-get install git-svn subversion Switch inside the PROJECT_FOLDER cd PROJECT_FOLDER Create the project path on the Subversion server (unfortunately the current git-svn plugin has a defect in comparison with TortoiseSVN). It is unable to store source code directly into the PROJECT_FOLDER. Instead, by default, it will upload all the code into PROJECT_FOLDER/trunk. svn mkdir --parents protocol:///path/to/repo/PROJECT_FOLDER/trunk -m "creating git repo placeholder"

在这里,中继在路径的末端是强制性的

Initialize the git-svn plugin context inside the .git folder git svn init -s protocol:///path/to/repo/PROJECT_FOLDER This is the place where trunk at the end of the path is unnecessary Fetch an empty Subversion repository information git svn fetch This step is helping to synchronize the Subversion server with the git-svn plugin. This is the moment when git-svn plugin establishes remotes/origin path and associates it with the trunk subfolder on the server side. Rebase old Git commits happened before the git-svn plugin became involved in the process (this step is optional) git rebase origin/trunk Add new/modified files to commit (this step is regular for Git activities and is optional) git add . Commit freshly added files into the local Git repository (this step is optional and is only applicable if step 7 has been used): git commit -m "Importing Git repository" Pushing all the project changes history into the Subversion server: git svn dcommit

如果您不想将在Git中所做的每个提交都提交到SVN存储库,该怎么办?如果您只想有选择地向管道发送提交,该怎么办?我有个更好的办法。

我保留了一个本地Git存储库,我所做的一切都是从SVN中获取和合并。通过这种方式,我可以确保包括所有与SVN相同的更改,但我将提交历史与SVN完全分开。

然后,我在一个单独的文件夹中保存一个单独的SVN本地工作副本。这就是我提交回SVN的文件,我只使用SVN命令行实用程序。

当我准备将本地Git存储库的状态提交到SVN时,我只需将所有乱七八糟的文件复制到本地SVN工作副本中,然后从那里使用SVN而不是Git提交它。

这样我就不需要做任何重基,因为重基就像冻结。