简体   繁体   English

GitFlow:先合并到 master 还是在产品发布后合并?

[英]GitFlow: merge to master first or after prod release?

Learning GitFlow and I have some concerns that I don't see addressed in any of the docs/articles I've read about it.在学习 GitFlow 时,我有一些担忧,但在我读过的任何文档/文章中都没有看到这些担忧。

At some point code on the develop branch needs to be deployed to a QA/staging environment and tested rigorously.在某些时候, develop分支上的代码需要部署到 QA/staging 环境并进行严格测试。 So with GitFlow you cut a release branch off of develop , and then you deploy release to said staging environment.因此,使用 GitFlow,您可以从develop中切出一个release分支,然后将release部署到所述暂存环境。

First, just wanted to clarify something real quick: the very first time a particular project/repo goes through this process, you'll actually be forking/creating this new release branch from develop , yes ?首先,只是想快速澄清一些事情:特定项目/回购第一次经历这个过程,你实际上是从develop分叉/创建这个新的release分支,吗? And that all other times in the future, you're simply merging develop into release , yes ?并且在未来的所有其他时间,您只是将develop合并release中,吗?

So then QA tests the release branch on the staging env, all looks good, and we're ready to deploy to prod.然后 QA 在暂存环境中测试release分支,一切看起来都很好,我们准备好部署到 prod。 Do you:你:

  • Deploy to prod and then merge release into master ?部署到 prod,然后release合并到master中? ; ; or或者
  • Merge release to master and then deploy to prod?合并releasemaster然后部署到 prod?

I ask because it seems like in the former case you would need to deploy the release branch to prod, then deploy to prod, and then merge to master .我问是因为在前一种情况下,您似乎需要release分支部署到 prod,然后部署到 prod,然后合并到master Which sounds OK, but often prod and non-prod environments are not identical and code that runs perfectly fine in staging chokes the second it fires up on prod servers.这听起来不错,但通常生产环境和非生产环境并不相同,并且在暂存中运行得很好的代码在生产服务器上第二次启动时会发生阻塞。 I know GitFlow supports the concepts of hotfix branches but they are reserved for minor fixes.我知道 GitFlow 支持热修复分支的概念,但它们是为小修复保留的。 In the case of a complicated fix that requires a rollback/backout release, we now have "dirty code" (code that breaks prod for some reason) merged into master .在需要回滚/退出版本的复杂修复的情况下,我们现在将“脏代码”(由于某种原因破坏产品的代码)合并到master中。

And in the latter case, it might take hours or even days (especially if you need to involve IT/Ops to do prod deploys) from the time you merge and put in the prod release request in, to the time the prod deploy actually occurs.在后一种情况下,从合并并放入产品发布请求到产品部署实际发生可能需要数小时甚至数天(尤其是如果您需要让 IT/Ops 参与产品部署) . And during this time you have a master branch that says "features X, Y and Z are in prod" but they are actually not.在此期间,您有一个master分支,上面写着“功能 X、Y 和 Z 正在生产中”,但实际上并没有。

I'm wondering if GitFlow actually solves this somehow or what the known workarounds to either case are.我想知道 GitFlow 是否真的以某种方式解决了这个问题,或者这两种情况的已知解决方法是什么。

The project I work in is very chaotic, decisions change in a matter of minutes , so my strategy is to procrastinate as much as possible software configuration management decisions.我工作的项目非常混乱,决策在几分钟内就会发生变化,所以我的策略是尽可能拖延软件配置管理决策。

Particularly, merging into master: we only merge to master after we deployed in production and we have a confirmation e-mail that smoke tests worked fine .特别是合并到 master:我们只有在部署到生产环境后才合并到 master,并且我们有一封确认电子邮件,表明冒烟测试工作正常 This way we embrace chaos by managing the risk of decision changes, rollbacks in the deploy, technical problems or whichever issue may happen.这样,我们通过管理决策变更、部署回滚、技术问题或任何可能发生的问题的风险来应对混乱。

At the beginning we merged into master before going into production, but technical issues, rollbacks, management decisions at the very last minute... caused lots of problems to us, so we changed the strategy, and it's been working fine for the last 3 years.一开始我们在进入生产之前合并到master,但是最后一分钟的技术问题,回滚,管理决策......给我们带来了很多问题,所以我们改变了策略,并且在过去的3年中一直运作良好年。

If, eventually, after going to production some regression is found, that's a hotfix and must be handled like that :)如果最终在投入生产后发现一些回归,那就是一个修补程序,必须像这样处理:)

The release branch that you create is a short lived one, similar to the feature branches that you create.您创建的发布分支是一个短暂的分支,类似于您创建的功能分支。 Once the release is finished, you delete the branch.发布完成后,删除分支。 For example, I would create a release/0.1.0 branch, do the work, and then merge.例如,我会创建一个release/0.1.0分支,完成工作,然后合并。

When deploying to production, I always take the code from the master branch, meaning that I merge the release branch into master first, before deploying.部署到生产时,我总是从 master 分支中获取代码,这意味着我在部署之前先将 release 分支合并到 master 中。

GitFlow is more about moving forward, not back. GitFlow 更多的是关于前进,而不是后退。 Hence why hotfixes are used to create fixes for issues that are identified.因此,为什么要使用修补程序来为已识别的问题创建修复程序。

In terms of time taken to get into Production, that is really not a concern of GitFlow, and i don't think it will provide much help in this area.就进入生产所需的时间而言,这真的不是 GitFlow 关心的问题,我认为它不会在这方面提供太多帮助。 This would be an issue for you regardless of which branching strategy you use.无论您使用哪种分支策略,这对您来说都是一个问题。

You'll actually be forking/creating this new release branch from develop, yes?你实际上会从开发分叉/创建这个新的发布分支,是吗?

That is correct.那是正确的。 The first time around your only option is to create the release branch off of your main branch, and that's what you'll be deploying for QA/Staging, and later on to Production.第一次你唯一的选择是从你的主分支创建release分支,这就是你将部署的 QA/Staging,然后部署到生产。

And that all other times in the future, you're simply merging develop into release, yes?并且在未来的所有其他时间,您只是将开发合并到发布,是吗?

It depends.这取决于。 According to the description of the Git Flow, the release branch is a short lived one.根据 Git Flow 的描述,release 分支是一个短暂的分支。 It may branch off of develop only, and merged into master .它可能只从develop分支出来,并合并到master In theory, release should be merged back into develop after your release is done, and then be removed .理论上, release应该在你的 release 完成后合并回develop ,然后被删除 The only thing that you should be merging into release is hotfix .您应该合并到发布中的唯一内容是hotfix This is a nice clean article about the flow.这是一篇关于流程的好文章

This varies from one team to the next.这因一支球队而异。 I've worked on teams that exactly follow the GitFlow description, and others that choose to just delete release and recreate it from develop as if it was the first time.我曾在完全遵循 GitFlow 描述的团队中工作,而其他人则选择只删除release并从开发中重新创建它,就好像这是第一次一样。

Deploy to prod and then merge release into master?;部署到 prod,然后将 release 合并到 master 中?; or Merge release to master and then deploy to prod?或合并发布到主然后部署到生产?

In theory, master should always contain production-ready code, and the only way to guarantee that is that what gets deployed to production is exactly what's in the master branch.从理论上讲,master 应该始终包含生产就绪代码,而确保这一点的唯一方法是部署到生产的内容正是master 分支中的内容。 That said, we probably can't give you perfect answers of what works for your team in particular.也就是说,我们可能无法为提供特别适合团队的完美答案。

For example, I currently work on a team with a CI/CD pipeline that leaves us no choice but to merge before: the deployment happens automatically from master .例如,我目前在一个拥有 CI/CD 管道的团队工作,这让我们别无选择,只能先合并:部署从master自动发生。 I've seen some teams where releases are too far apart, and feel more confident deploying the release branch instead and merging afterwards.我见过一些团队发布的版本相距太远,我更有信心部署release分支,然后再合并。 This avoids deploying a human error made during the release -> master merge (which probably includes nasty conflicts built up over time).这避免了部署在release期间出现的人为错误 -> master合并(这可能包括随着时间的推移而产生的令人讨厌的冲突)。

I believe that you should choose the solution that works best for you, as the GitFlow might not cover every possible scenario and context.我相信您应该选择最适合您的解决方案,因为 GitFlow 可能无法涵盖所有​​可能的场景和上下文。

Deploying from master is fine for small shops.从 master 部署适用于小商店。 In cases where you must support multiple versions, you should maintain and deploy from the release branch.在必须支持多个版本的情况下,您应该从发布分支进行维护和部署。

In my previous team, the branching strategy is creating a release branch and do the final tests against release branch, and merging release branch to master before deployment.Then do a production deployment with master branch.在我以前的团队中,分支策略是创建一个发布分支并对发布分支进行最终测试,并在部署之前将发布分支合并到主分支。然后使用主分支进行生产部署。

But my current team is using a different approach that is deploying with a release branch to production and merge release branch to master after successful prod deployment.但我目前的团队使用的是一种不同的方法,即在成功部署产品后,将发布分支部署到生产环境,并将发布分支合并到主分支。 The benefit of this method is making sure the code is working in real production environment so we can say the code has been run in production correctly and then merge the release branch to master, so everything in master is working in reality.这种方法的好处是确保代码在真实的生产环境中工作,所以我们可以说代码已经在生产中正确运行,然后将发布分支合并到 master,所以 master 中的一切都在现实中工作。 Another advantage of this approach is easily to rollback if something wrong with the deployment as just re-deploy with master branch.这种方法的另一个优点是,如果部署出现问题,只需使用主分支重新部署即可轻松回滚。

For previous approach, I have experiences on rolling back the change since the production environment is more complicated and the issue wasn't found in nonprod environment before deployment, so I needed to rebase/revert the change in master branch which means the master branch is broken already until I do the rebase/revert:(对于以前的方法,我有回滚更改的经验,因为生产环境更复杂,并且在部署之前在非生产环境中没有发现问题,所以我需要 rebase/revert master 分支中的更改,这意味着 master 分支是在我做 rebase/revert 之前已经坏了:(

The things I like to release on release branch and merge it back to master after prod deployment are easy rollback and making sure the code in master is correct by running the code in real production environment not only in nonprod environment.我喜欢在发布分支上发布并在产品部署后将其合并回母版的东西很容易回滚,并通过在实际生产环境中运行代码来确保母版中的代码正确,而不仅仅是在非产品环境中。

In the end, it's still depends on which approach suits your project/team.最后,它仍然取决于哪种方法适合您的项目/团队。

I think a reason why you deploy first and then merge is that because in your CI/CD pipelines you can do some smoke tests after deployment, and if things are unstable you can do a revert by just deploying what was in the master branch originally, since your pipeline failed, then the merge to master would not happen.我认为您首先部署然后合并的原因是因为在您的 CI/CD 管道中,您可以在部署后进行一些冒烟测试,如果事情不稳定,您可以通过部署最初在 master 分支中的内容来进行还原,由于您的管道失败,因此不会发生与 master 的合并。

If however you merge first and then deploy, then reverting could be tricky since you would have to revert the merge... So I think it makes sense to deploy from release and if things are stable, then you merge to master.但是,如果你先合并然后部署,那么恢复可能会很棘手,因为你必须恢复合并......所以我认为从发布部署是有意义的,如果事情稳定,那么你合并到 master。

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

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