简体   繁体   English

如何在受限分支上确保BitBucket拉取请求No-FF策略的1个合并提交?

[英]How to ensure 1 merge commit for BitBucket pull request No-FF strategy on restricted branch?

I'd like to always have a no fast-forward effect on the base branch (creates merge commit always). 我想始终对基分支没有快进效果(始终创建合并提交)。 Based on the following Bitbucket settings used by my team it appears sometimes 2 merge commits will need to be created in order for conflict-resolution. 根据我的团队使用的以下Bitbucket设置,似乎有时需要创建2个合并提交才能解决冲突。

Bitbucket Server Branch Settings Bitbucket服务器分支设置

  • Changes without a pull request - prevents pushing changes directly to the specified branch(es); 没有拉取请求的更改-防止将更改直接推送到指定分支; changes are allowed only with a pull request. 仅在请求请求时才允许进行更改。 Branch Permissions 分行权限

  • Merge Commit (--no-ff) Always create a new merge commit and update the target branch to it, even if the source branch is already up to date with the target branch. 合并提交 (--no-ff)始终创建一个新的合并提交并向其更新目标分支,即使源分支已经与目标分支保持最新。 Default Merge Strategy 默认合并策略

Since the base branch can only be changed via pull-requests, and it always creates a merge commit on PR-merge, therefore it appears pull requests that require manual conflict resolution will have to have 2 commits. 由于基本分支只能通过pull-requests进行更改,并且它始终在PR-merge上创建合并提交,因此,看来需要手动解决冲突的pull request必须进行2次提交。

Problematic Scenario example: 问题场景示例:

Here is the scenario: the base branch gets merged onto the feature branch to manually resolve the conflict, in this case the manually resolved conflicts result in a merge commit. 这是场景:基本分支合并到功能分支上以手动解决冲突,在这种情况下,手动解决的冲突导致合并提交。 Then after pushing the conflict-merge commit then the PR will be updated and ready to merge, and upon merging to base it would then create yet another merge commit (due to no-ff option). 然后,在推送冲突合并提交之后,PR将被更新并准备好进行合并,并且在合并为基础时,它将创建另一个合并提交(由于使用no-ff选项)。 Technically only 1 of those 2 commits were needed. 从技术上讲,仅需要这2个提交中的1个。 When done directly in git (without pull request and without locked down branch) this could have been achieved using no-ff by merging directly onto the base branch. 当直接在git中完成(没有拉取请求并且没有锁定分支)时,可以使用no-ff通过直接合并到基础分支来实现。

Is there something I'm missing here? 我在这里想念什么吗? Is there a way to achieve exactly 1 merge commit using Bitbucket Server pull request restrictions? 有没有一种方法可以使用Bitbucket Server拉取请求限制来实现完全1个合并提交?

This is the expect result if you have set merge changes into the base branch via PR and with no-ff merge strategy. 如果您已通过PR并使用no-ff合并策略将合并更改设置到基本分支中,则这是预期结果。

Assume the base branch is master branch, and the pull request is for merging feature branch into master branch, and the commit history as below: 假设基本分支是master分支,并且pull请求用于将feature分支合并到master分支,并且提交历史如下:

…---A---B---C---D     master
             \
              E---F  feature

If you resolve the merge conflict by merging master branch into feature branch with default merge strategy, and after completing the PR, then the commit history will as below (commit G is the first merged commit and commit H is the second merged commit): 如果通过使用默认的合并策略将master分支合并到feature分支中来解决合并冲突,并在完成PR之后,则提交历史将如下所示(commit G是第一个合并的提交,commit H是第二个合并的提交):

…---A---B---C-------D---H     master
             \       \ /
              E---F---G  feature

In order to make the commit history look clearly, you can change the way to resolve merge conflict by git cherry-pick or squash merge strategy . 为了使提交历史清晰可见,您可以通过git cherry-pick或squash合并策略更改解决合并冲突的方法

  • If resolve the merging feature into master branch's merge conflicts with git cherry-pick : 如果将合并功能解析为master分支与git cherry-pick的合并冲突:

     git checkout feature git cherry-pick D # resolve all conflicts git add . git cherry-pick --continue git push origin feature 

    After completing PR, the commit history will be: 完成PR后,提交历史记录将为:

     …---A---B---C---D-------M master \\ / E---F---D' feature 
  • If resolve the merging feature into master branch's merge conflicts with squash merge: 如果将合并功能解析为master分支与squash merge的合并冲突:

     git checkout feature git merge master --squash # resolve all merge conflicts git add . git commit git push origin feature 

    After completing PR, the commit history will be: 完成PR后,提交历史记录将为:

     …---A---B---C---D-------M2 master \\ / E---F---M1 feature 

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

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