简体   繁体   English

将本地Git存储库与主Subversion存储库一起使用

[英]Use local Git repository with a master Subversion repository

I have heard that it is possible to have a local Git repository on a developer machine, while keeping a master copy of the source code stored in a svn repository. 我听说可以在开发人员计算机上安装本地Git存储库,同时保留存储在svn存储库中的源代码的主副本。

A good use case would be that you have a central svn repository that each developer works with. 一个很好的用例是你有一个每个开发人员使用的中央svn存储库。 One developer goes offline occasionally and would like to track changes he/she makes while offline. 一位开发人员偶尔会离线,并希望跟踪他/她在离线时所做的更改。 When the developer is back online and has access to svn, their working copy modifications could be checked into svn. 当开发人员重新上线并可以访问svn时,他们的工作副本修改可以检入svn。 I'm fine with losing the history of changes that happened locally with Git, when the files are checked into svn. 当文件被检入svn时,我很好地失去了Git本地发生的变化的历史。

Can someone outline how best to pull this off? 有人可以概述如何最好地解决这个问题吗? Are there any pitfalls to working like this? 像这样工作有任何陷阱吗?

You could use something like this tutorial as a starting point. 您可以使用类似本教程的内容作为起点。 I also read this tutorial . 我也读过这个教程

There are several pitfalls to this mode of working. 这种工作方式有几个陷阱。 The most important one is that you cannot be using svn version 1.5 mergeinfo and expect this to survive through git. 最重要的一点是你不能使用svn 1.5版mergeinfo,并期望通过git生存。 This is a major drawback if you're using the (arguably fairly decent) svn 1.5 merge functionality. 如果你使用(可以说是相当不错的)svn 1.5合并功能,这是一个主要的缺点。

The man page for git-svn also contains some notes under the "caveats" that section that you should understand. git-svn的手册页还包含了一些您应该理解的“警告”部分下的注释。 Once I understood all the caveats I understood the benefits of using this setup to be less than the actual cost for my specific case. 一旦我理解了所有警告,我就明白使用此设置的好处是低于我特定情况的实际成本。 So I used my energy to convince the project to switch to git instead, something I just succeded in. 所以我用自己的精力来说服项目转而使用git,这是我刚刚成功完成的事情。

Say your SVN repo is at svn+ssh://username@svn_server/svn/your_repo 假设您的SVN 仓库位于svn + ssh:// username @svn_server / svn / your_repo
and your SVN repository has a "proper" layout (trunk, branches, tags) Here's workflow I've been using for few months now: 你的SVN存储库有一个“正确的”布局(主干,分支,标签)这是我几个月来一直使用的工作流程:
1. ' mkdir your_repo ' 1.'mkdir your_repo '
2. ' cd your_repo ' 2.'cd your_repo '
3. ' git svn clone -s svn+ssh://username@svn_server/svn/your_repo . 3.'git svn clone -s svn + ssh:// username @svn_server / svn / your_repo。 ' (mind the dot) '(记住点)
4. [wait a while depending on the size of your repository :)] 4. [等待一段时间,具体取决于您的存储库的大小:)]
now your GIT 'master' tracks the SVN trunk 现在你的GIT'master'跟踪SVN中继
you can also make a tracking branch like you'd normally do with git if you're working on some branch 如果你在某个分支上工作,你也可以像git一样使用git创建一个跟踪分支
5. the traditional hack hack hack 5.传统的hack hack hack
6. update your clone with ' git svn fetch && git svn rebase ' 6.使用' git svn fetch && git svn rebase '更新你的克隆
7. "push" your changes to svn with ' git svn dcommit ' 7.使用' git svn dcommit '将你的更改“推”到svn

More good stuff 更好的东西
Define following handy aliases in your .gitconfig: 在.gitconfig中定义以下方便的别名:
1. Alias ' spull ' which stands for svn-pull like this: ' spull = !git svn fetch && git svn rebase ' 1.别名' spull '代表svn-pull如下:' spull =!git svn fetch && git svn rebase '
2. Alias ' spush ' which stands for svn-push like this: ' spush = !git svn dcommit ' 2.别名' spush '代表svn-push,就像这样:' spush =!git svn dcommit '
These aliases turn the workflow in to pure effectiveness: clone / hack hack / spull / spush -> profit 这些别名转工作流程,以纯效益: 克隆 / 砍砍 / spull / spush - > 利润

svn:externals SVN:外部组件
I couldn't find a good solution for this in the internet, so made one myself :) 我无法在互联网上找到一个好的解决方案,所以自己做了一个:)
http://github.com/sushdm/git_svn_externals it's not yet perfect, but it should definetely make life a lot easier. http://github.com/sushdm/git_svn_externals它还不完美,但它应该能够让生活变得更加轻松。

Works for me perfectly well, hope it helps you. 非常适合我,希望它能帮到你。

One solution I would try is: 我会尝试的一个解决方案是:

  1. Checkout from central repo using SVN 使用SVN从中央仓库结帐
  2. git init to create local repo git init创建本地repo
  3. add .svn to .gitignore 将.svn添加到.gitignore
  4. git add * to add all files to local repo git add *将所有文件添加到本地仓库
  5. Do all your intermediate branches/commits/reverts in git. 用git做你所有的中间分支/提交/恢复。
  6. When you're done, commit back to the central repo using SVN. 完成后,使用SVN返回中央仓库。

I think the better use case for git-svn is if you are forced to work with a central svn repository, but you would like to personally work with git. 我认为git-svn更好的用例是你被迫使用中央svn存储库,但是你想亲自使用git。 Or perhaps most people on the team feel more comfortable working with svn at the moment. 或者也许团队中的大多数人现在更愿意使用svn。 Using git-svn you will not lose the history of commits made in the local git repository. 使用git-svn,您不会丢失在本地git存储库中提交的提交历史记录。

If you are setting up a new repository from scratch and / or have the freedom to choose, I would choose one or the other. 如果您从头开始设置新的存储库和/或可以自由选择,我会选择其中一个。 git-svn works well but you will always be fighting the 'impedance mis-match' between the two systems. git-svn运行良好,但你总是会对抗两个系统之间的“阻抗不匹配”。

If it is simply a centralized model you are looking to implement then a public git repository could be used as a central repository. 如果它只是一个您希望实现的集中模型,那么公共git存储库可以用作中央存储库。 See the Git User's Manual section on setting up a shared repository . 有关设置共享存储库的信息,请参阅Git用户手册部分。

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

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