git - 按规则分支时主分支的用途

标签 git merge version-control branch trunk

摘自文章 Source Control Done Right :

With the “create branch” button just a click away, there are a plethora of ways to incorrectly branch your codebase. But there are only two correct strategies – branching by rule and branching by exception – and both are related to isolating changes in releases. Because of this, a branch should always be identified by its corresponding release number.

The reason for this is simple: there’s only one trunk (mainline, root, parent, or whatever you want to call it), and the code under that trunk is either what’s in production now (the last deployed release), or what will be in production later (the next planned release). And that means you’re either always branching or only branching sometimes.

  • 异常分支策略:

Branching by exception strategy

  • 按规则分支策略:

Branching by rule

当您必须并行维护软件产品的多个版本时(除非您有软件即服务交付模型,否则这种情况很常见),按规则分支策略似乎是最好的选择最合适的*。但在这种情况下,如果您在专用环境中使用每个发布分支的所有标签的持续部署(例如您在2.2环境中自动部署所有2.2.x标签,在2.3环境中自动部署所有2.3.x标签) ,每个发布分支的所有标签也将自动 merge 到主分支中,因为主分支应该反射(reflect)生产中的内容。如果不同发布分支的标签在时间上交错,这将导致 merge 冲突(例如在上面的按规则分支图中,如果使用连续部署,则该标签序列将被 merge 到主分支中:2.2.1、2.2.2 、2.2.3、2.3.1、2.3.2、2.2.4、2.3.3、2.2.5等;但是由于没有使用持续部署,所以只部署了每个release分支的最后一个标签,因此自动 merge 进入master分支,所以不存在这个问题)。

那么,当使用按规则分支策略时,使用 master 分支的目的是什么? 在我看来,master 分支仅对具有单一发行版本的软件产品有意义一次和异常更多,也就是说当使用异常分支策略时。


* Github repository of the CPython interpreter是使用按规则分支策略的示例。

最佳答案

What is the purpose of using the master branch?

在 Git 中,按照惯例,master 是克隆后 check out 的默认分支(您可以更改它,但在这里,我们假设远程存储库将“master”作为其默认分支)

因此,使用 master 的目的是:您希望您的贡献者(世界上任何对您的存储库具有读取权限的人)在克隆您的存储库时看到什么。
它可以是最新的主要发布版本,也可以是最新的开发状态:这取决于您在 README 或“guidelines for repository contributors”中描述的内容。

关于git - 按规则分支时主分支的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55564689/

相关文章:

SVN合并branch to trunk导致文件冲突已解决

git - 是否有一个 gitflow 流程用于分支和错误修复与发布分支?

mongodb - 如何在不使用 $facet 的情况下组合两个 MongoDB 聚合管道查询的结果并对组合结果执行另一个聚合查询?

git - 理解 Git Hook - post-receive hook

merge - 如何使用 CMake 将我自己的 .o 文件与第 3 方静态库合并以创建新的合并静态库?

version-control - KDIFF合并中的A、B和C是什么

visual-studio - Visual Studio Lightswitch - 版本管理

git - 如何从 Git 导出所有更改/添加的文件?

Git merge 比较 from 到 含义

java - Git:重构文件名后无法清理工作副本