摘自文章 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.
- 异常分支策略:
- 按规则分支策略:
当您必须并行维护软件产品的多个版本时(除非您有软件即服务交付模型,否则这种情况很常见),按规则分支策略似乎是最好的选择最合适的*。但在这种情况下,如果您在专用环境中使用每个发布分支的所有标签的持续部署(例如您在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/