简体   繁体   English

Git 分支策略 - 合并时丢失更改

[英]Git branching strategy - losing changes on merge

We've got a branching strategy with develop, release, and master branches.我们有一个包含开发、发布和主分支的分支策略。 Features/bugs branch off of release.功能/错误从发布中分支出来。 When complete, they merge into develop for QA testing.完成后,它们合并到开发中以进行 QA 测试。 Once QA passes, they merge (directly from the feature/bug branch) into release for release regression testing.一旦 QA 通过,它们(直接从功能/错误分支)合并到发布中以进行发布回归测试。 Release merges to master after final regression testing.在最终回归测试后发布合并到主控。 Hotfixes branch off master, merge back into master.修补程序从 master 分支,合并回 master。

With all that said, we are sometimes losing changes in release and QA when merging branches in. Developers are merging from release into their branches prior to merging into QA and release, but never merging in from QA.尽管如此,在合并分支时,我们有时会丢失发布和 QA 的更改。开发人员在合并到 QA 和发布之前从发布合并到他们的分支,但从不从 QA 合并。

Are there any conceptual issues with this strategy?此策略是否存在任何概念问题? Any potential reasons why we may be losing those changes?我们可能会丢失这些更改的任何潜在原因?

Your strategy is sound, and has a name: gitworkflow , which allows to merge only the feature branch you want/need in QA or release (instead of merging everything from QA to release)您的策略是合理的,并且有一个名称: gitworkflow ,它允许仅合并您在QArelease中想要/需要的功能分支(而不是合并从 QA 到发布的所有内容)

But that does not account for any "lost changes": that would be caused by merge conflict resolution which somehow keep one change and override another concurrent change.但这并不能解释任何“丢失的更改”:这将是由合并冲突解决引起的,它以某种方式保留一个更改并覆盖另一个并发更改。

Developers are merging from release into their branches开发人员正在从发布合并到他们的分支

That is the only flaw I can see.这是我能看到的唯一缺陷。 No merge is ever made from release or master .没有releasemaster进行合并。 Those are branches you merge to , not from .这些是您合并to的分支,而不是from .

The best practice is to rebase a dev branch on top of their intended merge target ( QA or release ), and then merge them.最佳实践是在预期的合并目标( QArelease )之上重新构建一个dev分支,然后合并它们。

We've got a branching strategy with develop, release, and master branches.我们有一个包含开发、发布和主分支的分支策略。

That sounds a bit like Gitflow .这听起来有点像Gitflow But the rest of your description does not.但是您描述的 rest 没有。 So I am assuming you are using something else on purpose and did not just misunderstand Gitflow.因此,我假设您是故意使用其他东西,而不仅仅是误解了 Gitflow。 That is absolutely fine, but IMO your concept is flawed for some reasons.那绝对没问题,但是由于某些原因,IMO 您的概念存在缺陷。 I am saying that because you directly asked:我这么说是因为你直接问:

Are there any conceptual issues with this strategy?此策略是否存在任何概念问题?

So yes, there are.所以是的,有。

Features/bugs branch off of release.功能/错误从发布中分支出来。 When complete, they merge into develop for QA testing.完成后,它们合并到开发中以进行 QA 测试。

That sounds a bit weird.这听起来有点奇怪。 Features should branch off of develop, QA tested directly in their own branches and only merged back into develop after QA has passed, where subsequently you can do additional integration testing.功能应该从开发分支出来,QA 直接在他们自己的分支中测试,只有在 QA 通过后才合并回开发,随后您可以在其中进行额外的集成测试。

On a side note: In projects where I work as a coach, we usually have a rule that merges from subordinate (less stable) to higher-ranking (more stable) branches always have to be fast-forwards.附带说明:在我担任教练的项目中,我们通常有一条规则,即从下属(不太稳定)到更高级别(更稳定)的分支总是必须快进。 Ie, if during feature development some other features happen to have been QA-tested and merged back into develop earlier than the currently tested ones, the feature branch must be refreshed from development, re-tested as much as necessary and only then fast-forwarded back into develop.即,如果在功能开发过程中,某些其他功能碰巧已经过 QA 测试并比当前测试的功能更早地合并回开发中,则必须从开发中刷新功能分支,尽可能多地重新测试,然后才快速转发回到发展。 That means, both feature QA testing and integration testing are done in the feature branch.这意味着,功能 QA 测试和集成测试都在功能分支中完成。 A feature or bugfix is only merged back into development after it is clear that it does not only work in isolation but also integrated with all other work which was already accepted into development before.一个功能或错误修复只有在明确它不仅可以单独工作而且还可以与之前已经被接受到开发中的所有其他工作集成之后才被合并回开发中。 I call that the "no surprises" rule.我称之为“没有意外”规则。 The situation "oh, on the feature branch it was working, why does it not work on the development branch?"情况“哦,在功能分支上它正在工作,为什么它在开发分支上不起作用?” simply cannot occur and no additional post-merge integration testing is even necessary, because it was a fast-forward.根本不可能发生,甚至不需要额外的合并后集成测试,因为这是一个快进。

So this directly contradicts what VonC said in his answer:因此,这与 VonC 在他的回答中所说的直接相矛盾:

No merge is ever made from release or master.从发布版或主版中不会进行任何合并。 Those are branches you merge to, not from.这些是您合并的分支,而不是来自。

I could not disagree more.我不能再不同意了。 Subordinate branches should be refreshed from higher-ranking ones regularly, because by definition on higher-ranking ones there is always work that was accepted to be merged (or fast-forwarded) there before, ie it is inevitable that you have to integrate with them.应该定期从较高级别的分支刷新下级分支,因为根据较高级别的定义,总是有工作被接受合并(或快进)之前,即您不可避免地必须与它们集成. Merge conflicts or post-merge integration problems ought to be fixed in the feature or bugfix branch before accepting and merging them back into the higher-ranking branch.合并冲突或合并后集成问题应该在功能或错误修复分支中修复,然后再接受并将它们合并回更高级别的分支。 IMO it is an absolute no-no to mess up a higher-ranking branch with newly introduced instability and then clean up the mess there. IMO 绝对不能用新引入的不稳定性来搞乱一个更高级别的分支,然后清理那里的混乱。

Once QA passes, they merge (directly from the feature/bug branch) into release for release regression testing.一旦 QA 通过,它们(直接从功能/错误分支)合并到发布中以进行发布回归测试。

Before, you said that you do integration testing on develop, ie you resolve merge conflicts there which might be completely different from the ones (if any) you will have when merging the feature back into release.之前,您说过您在开发中进行集成测试,即您在那里解决合并冲突,这可能与您在将功能合并回发布时遇到的(如果有的话)完全不同。 Moreover, you are merging back something other than was integration-tested.此外,您正在合并经过集成测试以外的其他内容。 So even if there are no conflicts and everything goes super smoothly, what you are merging and what you have been testing is not the same.因此,即使没有冲突并且一切都非常顺利,您正在合并的内容和您一直在测试的内容是不一样的。 That is very dangerous IMO.这是非常危险的IMO。 In your setup, the release branch contains other things than develop, and you seem to abuse - sorry for the opinionated term, but I indeed hold that opinion - develop as some kind of conflict-resolving and integration-testing sandbox, only not to merge back to the release branch from there later.在您的设置中,发布分支包含除开发之外的其他内容,并且您似乎滥用了-对于自以为是的术语感到抱歉,但我确实持有这种观点-开发为某种解决冲突和集成测试的沙箱,只是不合并稍后从那里返回发布分支。

You have no clear hierarchy of branches like Gitflow or a simple feature branch workflow do.您没有像 Gitflow 或简单的功能分支工作流程那样的清晰的分支层次结构。 I think this is dangerous and calling for trouble.我认为这很危险,而且会带来麻烦。

Release merges to master after final regression testing.在最终回归测试后发布合并到主控。

See?看? That is another side effect: You QA-test the feature, then integration-test develop, merge something else, then have to re-test ("final regression testing") again, which should not even be necessary with a good, hierarchical branching and merging strategy.这是另一个副作用:您对功能进行 QA 测试,然后进行集成测试开发,合并其他内容,然后必须再次重新测试(“最终回归测试”),这对于良好的分层分支来说甚至是不必要的和合并策略。

Hotfixes branch off master, merge back into master.修补程序从 master 分支,合并回 master。

I want to say more about that, but in this case it is not the source of the problem, because at least this is hierarchical.我想说更多,但在这种情况下,它不是问题的根源,因为至少这是分层的。 You merge back to where you branched off of.你合并回到你分支的地方。 As long as you regularly refresh subordinate branches from master in order to also have the hotfixes there, OK, but only then.只要您定期从 master 刷新从属分支,以便在那里也有修补程序,好的,但只有这样。

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

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