49

我要将我的发布分支合并到master,我想知道在合并到master时是否应该将提交从开发压缩到单个合并提交。

关于 git flow 的一般文档包含来自 Atlassian 页面中的此类数据:

在此处输入图像描述

在这些图中,只有单个提交出现在 master 上,而不是所有为开发而进行的提交。

实际上,我喜欢拥有一个仅发布提交的主分支的想法。

合并到master时我应该保留所有关于develop的提交吗?还是在跟随 Gitflow 时合并到 master 之前压缩提交?

链接到源文章:Gitflow Workflow - Atlassian

4

3 回答 3

40

In my opinion, and bear in mind, this is just an opinion, and you will likely get different answers, you should NOT squash the commits when merging into master from the develop branch. Doing so would lose a lot of the history of the changes that have been made. For example, almost all the commits I make are tagged with an issue number, so that there is full trace-ability back through the git history into the issues that were raised, and why changes were made.

More to the point, you shouldn't be merging directly from develop into master. Assuming you are following git-flow, then this transition should be being done through a release branch.

If you had asked whether, when on a feature or hotfix branch, should the commits be squashed then that would have been a different answer. In these cases, arguably the branch should be small enough to warrant only a single commit, so in these situations, I almost always rebase and squash commits into a single one, prior to merging into the target branch.

于 2016-12-23T08:50:35.017 回答
38

master 分支用于维护发布记录,因此每个提交都应该代表来自组成发布版本的开发分支的一组压缩更改。

压缩提交可以更容易地查看发布中发生了哪些更改,并在必要时从发布提交创建修补程序分支。用发布版本号标记每个压缩的提交。

于 2018-02-21T11:35:28.383 回答
7

如果您在开发、发布分支和主控之间压缩合并,则很难将对发布分支的更改合并回开发而不会发生文件冲突。也很难将修补程序合并到开发中,然后通过发布将开发合并回主控。

于 2019-12-05T06:01:45.363 回答