简体   繁体   English

使用subgit将git分支合并到svn分支

[英]Merge git branch onto svn branch using subgit

I'm using the Subgit plugin for BitBucket to mirror an svn repository as a git repository. 我使用BitBucket的Subgit插件将svn存储库镜像为git存储库。 Only the trunk branch (called master in git) has been marked for synchronization, but developers using the git repository have created a feature branch and committed a dozen commits to the git branch (which is not being synchronized). 只有主干分支(在git中称为master)已被标记为同步,但是使用git存储库的开发人员已创建了一个功能分支,并向git分支(未同步)提交了十二个提交。

Now both branches have several commits and we want to merge the git feature branch back to the trunk svn branch. 现在,两个分支都有几次提交,我们想将git feature分支合并回主干svn分支。 The subgit docs are not entirely clear if the following would work: subgit文档尚不完全清楚,是否可以使用以下功能:

git checkout master
git merge feature
git push

One other thing to note is that merging will require a merge commit since there's a conflict that must be resolved. 要注意的另一件事是,合并将需要合并提交,因为必须解决冲突。

  • Is this workflow supported in subgit? subgit支持此工作流程吗?
  • Will this mess up the SVN repo? 这会搞乱SVN回购吗?
  • Will all the individual commits on the feature branch be preserved? 是否会保留功能分支上的所有个人提交?
  • Or should I just rebase the feature branch onto master and then push? 还是应该将功能分支重新设置到master上,然后再推送?

This workflow 这个工作流程

git checkout master
git merge feature
git push

is supported by SubGit (in this case it doesn't matter, but I recommend to to use 由SubGit支持(在这种情况下没有关系,但是我建议使用

git merge --no-ff feature

to prevent fast-forward merges); 防止快速合并); the result depends on your configuration. 结果取决于您的配置。 I'll describe several cases. 我将描述几种情况。

Case 1. (Not your case, but useful to know) If both trunk and the branch are configured to be synchronized by SubGit. 案例1.(不是你的情况,但需要了解的)如果两个主干和分支被配置成由SubGit同步。 In this case the effect is equivalent to "svn merge" command: svn:mergeinfo will be updated. 在这种情况下,效果等同于“ svn merge”命令: svn:mergeinfo将被更新。 Of course, individual commits in the feature branch will also get into SVN because the feature branch is configured to be synchronized. 当然,由于功能分支配置为同步,因此功能分支中的单个提交也将进入SVN。

Case 2. (Your case, I think, check 'shelves=' option to be sure) Only trunk is configured to be translated, the feature branch is not; 情况2。(我想您的情况是肯定的,请选中'shelves ='选项)仅将中继配置为要翻译,而功能分支未配置; and also you have 'shelves=' option set in SVN Mirror add-on settings for the repository, usually the option looks like: 而且你 “货架=”选项SVN镜设置附加设置存储库,通常的选择是这样的:

shelves = shelves/*:refs/shelves/*

but the exact value doesn't matter. 但是确切的值并不重要。 In this case "git push" will push all commits from both master and feature branch (even though you didn't push the feature branch explicitly), because the commits will be reachable by "merge commit parent" link. 在这种情况下,“ git push”将同时推送master和feature分支中的所有提交(即使您没有显式推送feature分支),因为可以通过“ merge commit parent”链接访问这些提交。 On the other hand, the feature branch Git reference won't be pushed, so SubGit can't know the name of the feature branch. 另一方面,要素分支Git参考不会被推送,因此SubGit 无法知道要素分支的名称 In this case SubGit will invent some temporary name in the 'shelves' namespace in SVN, eg shelves/shelf corresponding to the commits of the feature branch. 在这种情况下,SubGit将在SVN的“货架”名称空间中发明一些临时名称,例如,对应于功能分支提交的shelves/shelf Then it will translate these individual commits to SVN one-by-one. 然后, 它将这些单独的提交一对一地转换为SVN。 Finally it will create a merge commit in the SVN trunk, updating svn:mergeinfo ; 最后,它将在SVN干线上创建合并提交, 更新 svn:mergeinfo and after all it will delete that shelves/shelf in SVN (but you can refer to it using older revisions, Subversion never forgets). 毕竟它将删除 SVN中的那个shelves/shelf (但是您可以使用旧版本来引用它,Subversion永远不会忘记)。

To understand that better I recommend this post . 为了更好地理解,我推荐这篇文章 The second picture corresponds to this case, eg Case 2, while the first one to Case 1. 第二张图片对应于这种情况,例如案例2,而第一张图片对应于案例1。

Case 3. (Not your case but some users prefer this behaviour) Only trunk is configured to be translated, the feature branch is not; 情况3。(不是您的情况,但某些用户更喜欢这种行为)仅将中继配置为要翻译,而功能分支不是。 and also you do not have 'shelves=' option at all. 而且您根本没有 'shelves ='选项。 In this case all individual commits in the feature branch will be ignored in SVN, svn:mergeinfo will not be updated . 在这种情况下,功能分支中的所有单个提交都将在SVN中被忽略svn:mergeinfo不会被更新 So you will get all your changes in the SVN trunk, but not as individual commits but as a single SVN commit with all changes squashed together as if your were using 因此,您将在SVN主干中获得所有更改,但不是作为单个提交,而是作为单个SVN提交,所有更改都被压缩在一起,就好像您在使用

git merge --squash feature

instead of 代替

git merge feature

Note that on Git side the individual commits will still be preserved, they just won't be translated as individual revisions. 请注意,在Git方面,单个提交仍将保留,它们不会被翻译为单个修订。

I would also add that in SVN Mirror add-on not only this workflow is supported, but alternately you or your team members will create a Pull Request using Bitbucket Server UI and then merge it using UI. 我还要补充一点,在SVN Mirror插件中,不仅支持此工作流程,而且您或您的团队成员将使用Bitbucket Server UI创建一个Pull Request,然后使用UI合并它。 The behaviour in this case is approximately the same like when using "git merge" + "git push", ie it will be one of 3 Cases above. 这种情况下的行为与使用“ git merge” +“ git push”时的行为大致相同,即它将是上述3种情况之一。

What about your other questions: 您的其他问题呢?

  • Will this mess up the SVN repo? 这会搞乱SVN回购吗?

No it won't though it depends on your definition of mess. 不,这不会取决于您对混乱的定义。 Some people prefer "Case 2", calling "Case 3" the mess, other have the opposite opinion. 有些人喜欢“案例2”,称“案例3”一团糟,另一些人则持相反意见。 In either case you can configure the add-on to achieve behaviour you want. 无论哪种情况,您都可以配置加载项以实现所需的行为。

  • Will all the individual commits on the feature branch be preserved? 是否会保留功能分支上的所有个人提交?

In Cases 1 and 2 --- yes, in Case 3 --- no, they will be squashed to a single SVN revision. 在情况1和2中-是,在情况3中-不,它们将被压缩为单个SVN版本。 In all cases individual Git commits will be preserved as is. 在所有情况下,单个Git提交都将被保留。

  • Or should I just rebase the feature branch onto master and then push? 还是应该将功能分支重新设置到master上,然后再推送?

You can, but I wouldn't recommend you to do that. 您可以,但是我不建议您这样做。 In general I recommed to use git pull --rebase instead of just git pull . 通常,我建议使用git pull --rebase而不是git pull But when merging a feature branch it's better to merge it than to rebase it. 但是,合并功能分支时,合并它比重新设置基础更好。 If you rebase it, you'll see individual commits from the feature branch directly in the master (and hence in SVN trunk), this part is ok. 如果重新设置基础,您将直接在master中(因此在SVN干线中)看到来自功能分支的单个提交,这部分就可以了。 But the feature branch reference will be updated and you will have to either 但是功能分支参考将被更新,您将必须

  1. Push the updated feature branch reference with --force option, what's not recommended in general; 使用--force选项推送更新的功能分支引用,一般不建议这样做; OR 要么
  2. Leave the feature branch as is, thus having inconsistent feature branch reference locally and its commits repeatet twice: in 'master' and the feature branch. 保持要素分支不变,从而在本地具有不一致的要素分支引用,并且两次提交重复序列:在“主”和要素分支中。

This doesn't relate to SubGit (SubGit will just translate to SVN trunk what it will find in the 'master'), but will cause inconvenience in pure Git. 这与SubGit无关(SubGit只会转换为SVN干线,它将在“主”中找到),但会给纯Git带来不便。

I'm one of SubGit developers. 我是SubGit开发人员之一。

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

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