简体   繁体   English

将git存储库迁移到现有SVN存储库的分支

[英]Migrating a git repository to a branch of an existing SVN repository

Recently, I have been working on a Java project for my company. 最近,我一直在为我的公司从事Java项目。 For this project, they have chosen to use SVN as a version control system. 对于这个项目,他们选择使用SVN作为版本控制系统。 In the beginning, however, I did not have any access to this SVN repository. 但是,在一开始,我没有对该SVN信息库的任何访问权限。 Therefore I have been working locally on my own computer on some snapshot of this repository, which was provided to me by the lead developer. 因此,我一直在自己的计算机上本地工作于该存储库的某些快照,该快照由主要开发人员提供。 Since I have a lot of experience with git (and none with SVN), I have been using git to track the changes I have made to the project. 由于我对git有很多经验(而对SVN则没有经验),因此我一直在使用git来跟踪对项目所做的更改。

At the moment, the time has come to integrate my changes into the existing SVN repository. 目前,是时候将我的更改集成到现有SVN存储库中了。 According to the lead developer, I have to push my changes to a personal branch of the SVN repository, so that he can check my changes before merging them into the master branch. 根据主要开发人员的说法,我必须将更改推送到SVN存储库的个人分支,以便他可以在将更改合并到master分支之前检查我的更改。

What would be the best strategy to achieve this? 实现这一目标的最佳策略是什么? Would it be a good idea to generate a set of patches from git that are compatible with SVN? 从git生成与SVN兼容的补丁集是一个好主意吗? This would allow me to check out the latest version from SVN and to incremently try to apply each of the git commits I have made. 这将使我能够从SVN中检出最新版本,并逐步尝试应用我所做的每个git提交。

Another idea that came up, was to import my git repository into a local SVN repository and then to try to migrate this local SVN repository into the branch of the remote SVN repository. 出现的另一个想法是将git存储库导入本地SVN存储库,然后尝试将该本地SVN存储库迁移到远程SVN存储库的分支中。 I have no idea, however, if this could work at all. 但是,我完全不知道这是否可行。

Any help would be greatly appreciated!! 任何帮助将不胜感激!!

If there is a slightest chance of further work with that project, I would strongly recommend using git-svn. 如果极有可能进一步开展该项目,我强烈建议您使用git-svn。 This way you retain much of the power of git locally (except for merges - rebases only to/from svn), while still collaborating via svn. 这样,您可以在本地保留git的大部分功能(合并除外-仅对svn进行基础调整),同时仍可以通过svn进行协作。

The steps could be like following, but I am writing from memory and have no svn to check against. 这些步骤可能像下面这样,但是我是从内存中写入的,并且没有要检查的svn。

First, clone the svn project. 首先,克隆svn项目。 -s assumes standard ./trunk ./branches/* ./tags structure: -s假定标准./trunk ./branches/* ./tags结构:

git svn clone -s <path to SVN> sync_repo
cd sync_repo

Now we need to find the git point to which you will be applying your work. 现在,我们需要找到将您的工作应用到的git点。 Ideally, you should know the svn revision, snapshot of which the Team Lead provided you with initially, with which you do: 理想情况下,您应该知道svn修订版,团队负责人最初为您提供svn修订版的快照,您可以使用该快照:

 git svn find-rev r<svn revision>
 git branch my_git_reintegration <SHA1 we've just found, otherwise svn/trunk or some other reasonable revision>

Next we need to pull your changes from your local git: 接下来,我们需要从本地git中提取您的更改:

git remote add my_origin <path to your original git repo>
git fetch my_origin

And rebase your changes on top of your new branch: 并在新分支的基础上重新进行更改:

git rebase my_git_reintegration my_origin/master 

if you were lucky when choosing the my_reintegration point, you should have no merge conflicts during the rebase. 如果在选择my_reintegration点时很幸运,那么在my_reintegration期间应该没有合并冲突。 After the rebase we'll move the my_reintegration accordingly: 重新设置my_reintegration之后,我们将相应地移动my_reintegration

git push . HEAD:my_reintegration 

At this point you have my_reintegration containing your git changes, but possibly on top of an outdated svn commit. 此时,您的my_reintegration包含git更改,但可能在过时的svn commit之上。 Next, let's create a new svn branch you will be pushing your contributions to. 接下来,让我们创建一个新的svn分支,您将在其中进行贡献。 I'll assume you will branch off trunk: 我假设您会分支:

git checkout origin/trunk 
git svn branch my_svn_integration_branch
#those might be not necessary, but just in case 
git svn fetch

And now let's rebase our original changes onto this branch and push it to svn: 现在,让我们将原始更改基于此分支,并将其推送到svn:

git rebase origin/my_svn_integration_branch my_git_reintegration
#possibly resolve conflicts
#just for a safety, check the svn branch we target - should be my_svn_integration_branch
git svn info
#go!
git svn dcommit

at this point you should have your changes at svn's my_svn_integration_branch , you may delete your original git repository and keep using this one instead. 此时,您应该在svn的my_svn_integration_branch更改,您可以删除原始的git存储库,并继续使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM