Google's Trunk Based Development - 你是否直接将代码推送到发布分支而不是主干?

Google's Trunk Based Development - Do you push code directly to release branch instead of trunk?

我正在学习Google的trunk based development

In trunk-based development, developers push code directly into trunk. Changes made in the release branches—snapshots of the code when it's ready to be released—are usually merged back to trunk (depicted by the downward arrows) as soon as possible. In this approach, there are cases where bug fixes must be cherry picked and merged into releases (depicted by the upward arrow), but these cases are not as frequent as the development of new features in trunk.

它指出

changes made in the release branches—snapshots of the code when it's ready to be released—are usually merged back to trunk (depicted by the downward arrows) as soon as possible

我很困惑,因为就在那之前,它声明开发人员将代码直接推送到主干中。

  1. 代码应该直接推送到主干,怎么会被推送到发布分支?

  2. 为什么会挑选错误修复并合并到发布分支中这意味着错误修复是在发布分支中完成的,并且该发布分支已合并到主分支中?

  3. 假设代码没有直接推送到发布分支,为什么发布分支会合并回 master/trunk 如果它是从 master 分支出来的?

  1. How is it that code would be pushed to a release branch if it is supposed to be pushed directly to trunk?

发布分支的目标是让您专注于为发布准备软件,而不必担心 trunk 中发生的事情。当团队的其他成员通过直接提交给 trunk 继续致力于下一个版本时,您 稳定 通过修复 [=] 中任何剩余的错误来选择发布的快照12=]分支。

在此稳定过程中,您可能会发现 trunk 中也存在的错误。发生这种情况时,您需要 合并 release 分支回到 trunk 以整合这些错误修复。

  1. Why would bug fixes be cherry picked and merged into release branches it's implied that bug fixes are done in a release branch and that release branch is merged to master?

当您致力于稳定 release 分支中的软件时,团队的其他成员可能会在 trunk 中发现 release 中也存在的错误。如果发生这种情况,您将希望在发布中集成错误修复——但是,您不能只是将 trunk 合并到 release,因为那样会带来团队一直以来的所有新东西在您准备发布时继续工作。因此,相反,您 cherry-pick 只是修复错误的提交,仅此而已。

  1. Assuming code is not directly pushed to a release branch, why would the release branch be merged back into master/trunk if it was forked from master?

参见第 1 个答案。请注意,如果主干中的代码与最初为发布选择的代码相距太远,将发布分支合并回主干可能会导致大量合并冲突。例如,您可能已修复 release 中的错误,但由于重构,修改后的文件不再存在于 trunk 中。

还值得一提的是,发布分支并不总是值得额外的开销。您链接到 offers an example 的文档:

In cases where releases happen multiple times a day, release branches are not required at all, because changes can be pushed directly into master and deployed from there.

trunk-based development 的目标是通过将必须维护的分支数量减少到仅一个.[=29 来简化软件开发过程=]