简体   繁体   English

用于修补程序的 git 合并分支

[英]git merge branching for hotfixes

We have 3 branches (master, acpt, devl) and corresponding environments: production, acpt and devl.我们有 3 个分支(master、acpt、devl)和对应的环境:production、acpt 和 devl。 Our team has multiple developers.我们的团队有多个开发人员。 Trying to figure out how best development model to use to address the following scenario试图找出如何使用最佳开发模型来解决以下情况

devl has the following commits: A,B,C devl 有以下提交:A、B、C
acpt has: A acpt有:A
master has: A主人有:A

I have a hotfix commit that needs to be pushed to master.我有一个需要推送到 master 的修补程序提交。 I have created a new branch called hotfix using master, made the changes with commit D.我使用 master 创建了一个名为 hotfix 的新分支,并使用 commit D 进行了更改。

Should I merge the hotfix branch to master, acpt and devl?我应该将修补程序分支合并到 master、acpt 和 devl 吗? I guess the merge into acpt and master will work fine.我想合并到 acpt 和 master 会正常工作。 But since devl has already moved ahead to C, will devl have A,D,B,C or A,B,C,D ?但是既然 devl 已经前进到 C,那么 devl 会有 A,D,B,C 或 A,B,C,D 吗? Trying to figure out the best practice.试图找出最佳实践。

Note: Raymond Chen's"stop cherry-picking, start merging" describes this better than I can in the space I have here.注意:Raymond Chen 的“停止挑选,开始合并”比我在这里的空间更好地描述了这一点。

I believe the "right" work-flow for this is to merge fixes that are made at the point the bug is introduced .我相信“正确”的工作流程是合并在引入错误时所做的修复

You have described three groups that have access to a common repository as having access to a total of three commits.您已经将可以访问公共存储库的三个组描述为可以访问总共三个提交。 That's not a very realistic scenario: a typical Git repository will by this point have hundreds or thousands of commits.这不是一个非常现实的场景:一个典型的 Git 存储库此时将有数百或数千次提交。 It does suffice to draw the problem, but I think it's better to draw, say, six or more commits.绘制问题就足够了,但我认为最好绘制六个或更多提交。 I've drawn eight below to start with.我在下面画了八个。

(I also won't use your branch names; in fact, I'll just use one, to start with.) (我也不会使用你的分支名称;事实上,我只会使用一个,开始。)

Let's draw what we might have:让我们画出我们可能拥有的东西:

                   I--J--K   <-- develop
                  /
...--D--E--F--G--H   <-- tag:v1.0

The tag v1.0 is the particular commit that has been released as version 1.0.标签v1.0是作为 1.0 版发布的特定提交。 Meanwhile, developers continued developing and have made three new commits.同时,开发人员继续开发并进行了三个新的提交。

A customer now calls support and says that some particular command or feature has some particular bug.客户现在致电支持并说某些特定命令或功能存在某些特定错误。 This bug is now logged as bug #1234.此错误现在记录为错误 #1234。 The support and/or developer folks analyze the bug and find that the bug was introduced in commit F .支持人员和/或开发人员分析该错误并发现该错误是在提交F中引入的。 Here is what they should do:这是他们应该做的:

                  I--J--K   <-- develop
                 /
             G--H   <-- tag:v1.0
            /
...--D--E--F   <-- fixes/bug-1234

That is, we now have a new branch name in the fixes/ name-space, with the bug ID in it.也就是说,我们现在在fixes/命名空间中有一个新的分支名称,其中包含错误 ID。 We now come up with a fix for the bug and commit it, making a new commit with its new and unique hash ID.我们现在想出修复该错误并提交它,使用其新的和唯一的哈希 ID 进行新的提交。 Meanwhile the development group has already added a new commit L :同时开发组已经添加了一个新的提交L

                  I--J--K--L   <-- develop
                 /
             G--H   <-- tag:v1.0
            /
...--D--E--F--F1   <-- fixes/bug-1234

We test the fix, perhaps by merging it into commit H under a new release candidate branch ( rc/1.1 ), and giving the resulting merge commit to the testing group:我们测试修复,可能通过将其合并到新的候选发布分支( rc/1.1 )下的提交H ,并将生成的合并提交提供给测试组:

                    I--J--K--L   <-- develop
                   /
               G--H   <-- tag:v1.0
              /    \
             /   _--M   <-- rc/1.1
            /   /
...--D--E--F--F1   <-- fixes/bug-1234

If all goes well, release candidate 1.1 becomes the release tagged 1.1 (perhaps after also adding more fixes but these are not drawn here):如果一切顺利,候选版本 1.1 将成为标记为 1.1 的版本(也许还添加了更多修复,但此处未绘制):

                 I--J--K--L   <-- develop
                /
               G--H   <-- tag:v1.0
              /    \
             /   _--M   <-- rc/1.1, tag:v1.1
            /   /
...--D--E--F--F1   <-- fixes/bug-1234

(At this point the release candidate branch name can be deleted—it's no longer doing any good. It was just there to test M and maybe other merges as well.) (此时可以删除候选发布分支名称——它不再有任何好处。它只是为了测试M和其他合并。)

It is now time to merge commit F1 , the fix for the bug, into the mainline development as well.现在是时候将提交F1 (该错误的修复程序)也合并到主线开发中了。 This is hard to draw!这很难画! Here is an attempt:这是一个尝试:

                 I--J--K--L------__
                /                  \
               G--H   <-- tag:v1.0  \
              /    \                 \
             /   _--M   <-- tag:v1.1  \
            /   /_____-----------------N   <-- develop
...--D--E--F--F1   <-- fixes/bug-1234

If a bug is discovered in commit D or E or G , we can label that commit with fixes/bug-1235 , fix it, and merge the fix into a release candidate and/or the develop branch as well.如果在提交DEG发现错误,我们可以用 fix fixes/bug-1235标记该提交,修复它,并将修复合并到候选发布和/或develop分支中。 The drawing will get very messy, but Git will do the best possible job of merging, automatically, in each case.绘图会变得非常混乱,但 Git 会在每种情况下自动地尽最大可能地进行合并。

It is also relatively easy to automatically identify which tags and/or branches have a fix merged into them.自动识别哪些标签和/或分支具有合并到其中的修复程序也相对容易。 Commit F1 is now in the ancestry of develop , so it is merged there. Commit F1现在是develop的祖先,所以它在那里合并。 It is in the ancestry tag v1.1 , and not in the ancestry of tag v1.0 , so customers with v1.0 who have bug #1234 should upgrade to v1.1.在祖先标签v1.1 ,而不是在标签的祖先v1.0 ,因此与V1.0客户谁拥有了bug#1234应该升级到1.1版。

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

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