简体   繁体   English

如何使用Git分支/合并来克服开发分支中的bug提交?

[英]How to hurdle buggy commits in a develop branch using Git branching/merging?

I'm looking into different Git branching strategies and I keep getting stuck at one point. 我正在研究不同的Git分支策略,但我始终停留在某一点。 Let's say you have a master branch. 假设您有一个master分支。 Additionally, you have a develop branch, which is a branch from master. 此外,您还有一个develop分支,它是master的一个分支。 There are feature/topic branches: 有功能/主题分支:

  • FixFrontEnd FixFrontEnd
  • FixBackEnd FixBackEnd
  • ChangeConfig 更改配置

Three different developers do each change. 每个更改由三个不同的开发人员进行。 The ChangeConfig developer finishes quickly, commits, and merges into the develop branch. ChangeConfig开发人员可以快速完成,提交并合并到developer分支中。 That develop branch is now built and deployed to the Dev environment. 现在,该develop分支已构建并部署到Dev环境。 Someone tests out this new config and it's approved to move from Dev to the QA environment. 有人对此新配置进行了测试,并批准将其从Dev迁移到QA环境。 The same success is found for the FixFrontEnd and FixBackEnd branches. 在FixFrontEnd和FixBackEnd分支中发现了相同的成功。 They eventually move along up to QA. 他们最终进行了质量检查。

Priorities change the next and the three fixes/features are left sitting in QA. 优先级将在下一个更改,而三个修订/功能将留在质量检查中。 A new YetAnotherChange fix/feature makes it to QA. 新的YetAnotherChange修复/功能使其可以进行质量检查。 We've found issues with FixFrontEnd and ChangeConfig in QA. 我们在质量检查中发现了FixFrontEnd和ChangeConfig的问题。 However, YetAnotherChange must go to Production ASAP. 但是,YetAnotherChange必须尽快进行生产。

Everything I'm reading says that the develop branch is merged into the master branch, a new build is created for production using master, and it's deployed. 我正在阅读的所有内容都表明,develop分支已合并到master分支中,使用master创建了一个用于生产的新构建,并对其进行了部署。 Wouldn't FixFrontEnd and ChangeConfig get dragged along in the merge to master? FixFrontEnd和ChangeConfig不会在合并中拖到主站吗? How is everyone approaching this? 大家如何处理?

Cherry picking seems to be a complex choice. 采摘樱桃似乎是一个复杂的选择。 I'd like some good idea on how to solve this issue. 我想要一些有关如何解决此问题的好主意。 I'm looking for a simple solution. 我正在寻找一个简单的解决方案。 Additionally, let's say that we were able to cherry pick commits. 另外,假设我们能够挑选提交。 How can we truly trust that what's cherry picked and built in will work the same way as it did when we built using the develop branch? 我们如何才能真正相信,挑选和内置的Cherry的工作方式与使用developer分支进行构建时的运作方式一样? Am I getting lost in the woods here somewhere? 我在这里的树林里迷路了吗?

So you want to make changes to production without changes from FixFrontEnd and ChangeConfig branches . 因此,您想对生产进行更改, 而无需从FixFrontEnd和ChangeConfig分支进行更改 You can use the way to fix it. 您可以使用该方法进行修复。 Let's illustrate by below graph: 让我们通过下图进行说明:

A---B---C master
 \
  D----E----F----G ----L  develop
      /     |     \     \
     H      I      J     K

Assume commit histories from each fix/feature branches as: 假设每个修订/功能分支的提交历史记录如下:

ChangeConfig: H and then merge to develop branch ChangeConfig: H然后合并以开发分支

FixFrontEnd: I and then merge to develop branch FixFrontEnd:我然后合并以开发分支

FixBackEnd: J and then merge to develop branch FixBackEnd: J然后合并以开发分支

YetAnotherChange: K and then merge to develop branch YetAnotherChange: K,然后合并以开发分支

You just need to find the commit ID for D, F and L, then use git rebase --onto <commit id for D> <commit id for F> <commit id for L> , the develop branch will not contain the changes from FixFrontEnd and ChangeConfig branches. 您只需要找到D,F和L的提交ID,然后使用git rebase --onto <commit id for D> <commit id for F> <commit id for L> ,develop分支将不包含来自FixFrontEnd和ChangeConfig分支。 And it can go to production. 它可以投入生产。 The graph will equal to: 该图将等于:

A---B---C master
 \
  D ----G ----L  develop
         \     \
          J     K

note: during rebasing, there may has conflicted file, you need to use git add <conflicted filename> and git rebase --continue , then the rebase will go on. 注意:在重新基准化期间,可能有冲突的文件,您需要使用git add <conflicted filename>git rebase --continue ,然后重新git rebase --continue将继续。

Everything I'm reading says that the develop branch is merged into the master branch 我正在阅读的所有内容都表明,develop分支已合并到master分支中

Not really: you can: 并非如此:您可以:

  • rebase YetAnotherChange on top of master (and then fast-forward master to YetAnotherChange HEAD) 在主YetAnotherChangeYetAnotherChange的基础(然后将主YetAnotherChange快速转发到YetAnotherChange HEAD)
  • merge master back into develop 合并master回到develop
  • rebase the remaining feature branches on top of develop . develop剩余的功能分支。

Any rebasing operation will change the history of those branches, so it needs to be done with a good communication to the developers working on those branches for them to reset their working tree to the new branch HEAD. 任何重新定基操作都会更改这些分支的历史记录,因此需要与那些分支上的开发人员进行良好的沟通,以便他们将其工作树重置为新的分支HEAD。

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

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