简体   繁体   English

从两个不同的代码行(常规发布分支和修补程序分支)合并到Prod分支的Git策略

[英]Git strategy for merging to a Prod branch from two different code lines (regular release branch and a hotfix branch)

Our long running git branches are Master , UAT , and Prod such that new functionality is worked on and committed initially to Master, promoted to UAT (when ready for UAT) then promoted to Prod (when ready for Production). 我们长期运行的git分支是MasterUATProd ,因此新功能最初用于Master,升级到UAT(准备好UAT时),然后升级到Prod(准备生产时)。 We now need the ability to create hotfixes in production. 我们现在需要能够在生产中创建修补程序。 We are planning to create a Hotfix branch that links up with the Prod branch. 我们计划创建一个与Prod分支链接的Hotfix分支。 In addition to being long running, these branches are separate from each other in that merges are done using "non-fast-forward" merges to keep the branches separate (so that we can see easily what activity has happened on each branch, eg a code promotion from Master to UAT, etc). 除了长时间运行之外,这些分支是彼此分离的,因为合并是使用“非快进”合并来保持分支分开(这样我们可以很容易地看到每个分支上发生了什么活动,例如代码升级从Master到UAT等)。

The following shows the flow of commits for one regular development release which ended up needing a hotfix. 下面显示了一个常规开发版本的提交流程,最终需要一个修补程序。 Master has the majority of commits as development is happening all the time. 随着开发的不断发展,Master拥有大多数提交。 UAT and Prod only have commits that represent code promotions. UAT和Prod只有代表代码促销的提交。 When a hotfix is needed, we merge from prod to hotfix, make the change on the hotfix branch, test it in a hotfix environment, then merge it into prod. 当需要修补程序时,我们从prod合并到修补程序,在修补程序分支上进行更改,在修补程序环境中测试它,然后将其合并到prod中。

hotfix ----------------------o-o----------   [1 commit for the merge prod->hotfix to get the latest state of prod into the hotfix environment, 1 commit of a bugfix to the hotfix environment]
prod   --------------------o-----o--------   [1 commit for the promotion uat-> prod to get the latest uat-tested code into prod, 1 commit for the promotion of the bugfix hotfix->prod]
uat    -----------------o-----------------   [1 commit for the promotion of master->uat of 4 master commits]
master --o---o---o---o----o-o--o---o-o--o-   [10 commits of new functionality]

Note after a hotfix, the hotfix change is manually incorporated into the master branch. 注意在修补程序后,修补程序更改手动合并到主分支。 This is because depending on the time the hotfix went out and the state of the current development line (it could be months later), the code could be too divergent between Master and Hotfix, and an automatic merge from Hotfix to Master may not make sense. 这是因为取决于修补程序发出的时间和当前开发行的状态(可能是几个月后),主代码和修补程序之间的代码可能过于分歧,并且从Hotfix到Master的自动合并可能没有意义。 Because of this, for the merge from UAT to PROD, from PROD to HOTFIX, and from HOTFIX to PROD, we will be NOT be doing a regular git merge, but will instead use the git merge -s theirs strategy as documented here: git command for making one branch like another (We will specifically be doing simulation #3). 因此,对于从UAT到PROD,从PROD到HOTFIX,从HOTFIX到PROD的合并,我们将不会进行常规的git合并,而是使用git merge -这里记录的策略git使一个分支像另一个分支的命令 (我们将专门做模拟#3)。

What this strategy does is say "please merge in all changes from upstream into downstream and wipe out the state of downstream and replace it with exactly what is coming from the upstream". 这个策略的作用是说“请合并从上游到下游的所有变化,消除下游的状态,并将其替换为来自上游的确切内容”。 So when we go from UAT to PROD using this strategy we basically say "make PROD look EXACTLY like UAT". 因此,当我们使用这种策略从UAT转到PROD时,我们基本上会说“让PROD看起来像UAT一样”。 This ensures that what gets into Production is exactly the state of the code that was in UAT. 这确保了生产中的内容正是UAT中代码的状态。

Is the git merge -s theirs strategy the right way to do this sort of a merge strategy when you have two branches bringing in changes into production (one for regular releases and one for hotfixes) like this? 当你有两个分支将生产变更(一个用于常规版本,一个用于修补程序)这样的时候,git合并 - 他们的战略是做这种合并策略的正确方法吗?

If we had no hotfix branch, we would simply do a regular (non-fast-forward) merge from master to uat to prod and not use the git merge -s theirs strategy, as it would not be needed. 如果我们没有修补程序分支,我们只需要执行从master到uat到prod的常规(非快进)合并,而不是使用git merge -s theirs策略,因为它不需要。

You have three options: 你有三个选择:

  • either you just reset your branch to the new version. 要么你只是将你的分支重置为新版本。 (Which seems to be no option in your case.) (在你的情况下似乎没有选择。)
  • you use your "theirs strategy" to tell git "throw away the old version and replace it with the new one" (but git does not support this easily) 你使用你的“他们的策略”告诉git“扔掉旧版本并用新版本替换它”(但git不支持这个)
  • or you "invalidate" the hotfix change for master by merging PROD to master with the --ours option. 或者通过使用--ours选项将PROD合并到master来“使”master的修补程序更改“无效”。

If a regular merge from PROD to master is possible, do it. 如果可以从PROD到master进行定期合并,请执行此操作。 Otherwise merge with --ours and manually do the corresponding changes on master. 否则与--ours合并并在master上手动执行相应的更改。

Please think about your branching strategy. 请考虑一下您的分支策略。 A strategy which is perfect for one kind of project might be a real burden for another project. 对于某种项目而言,完美的策略可能是另一个项目的真正负担。

In your case I would suggest one development branch (eg master) with the normal develpment and for each release a separate branch (name based on the release). 在你的情况下,我会建议一个开发分支(例如master)与正常的开发,并为每个版本一个单独的分支(基于发布的名称)。

The release branch starts at master and enters UAT. 发布分支从master开始并进入UAT。 There minor fixes can be applied for issues found at this phase. 可以对此阶段发现的问题应用小修复。 Afterward it enters production, where any hotfixes can be applied directly. 然后它进入生产,可以直接应用任何修补程序。

There is really no good reason to link commits of two different releases in your case. 在您的案例中,没有充分的理由将两个不同版本的提交链接起来。

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

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