简体   繁体   English

Git Merge分支还原工作流程

[英]Git Merge Branch Revert Workflow

Here's our Scenario: 这是我们的方案:

Developers fork off Master into a new Branch and develop some code. 开发人员将Master分支到新的Branch中并开发一些代码。 Master progresses. 大师进步。 When it passes QA, and gets merged into Master, a complete regression test is run. 当它通过质量检查并合并到Master后,将运行完整的回归测试。 Sometimes, one branch (of several being merged/tested that release) fails regression. 有时,一个分支(其中几个正在合并/测试该版本)无法通过回归。 So we want to revert that merge and continue release the rest of the code. 因此,我们要还原该合并,并继续发布其余代码。 Typically, just something needs to be tweaked in the original development branched, QA'd again, and then remerged into master, but because Master reverted the changes originally most of the branches changes are wiped out. 通常,只需在原始开发分支中进行一些调整,然后再次进行质量检查,然后重新合并到master中即可,但是由于Master恢复了原来的更改,因此大部分分支更改都被清除了。 How best to re-merge this dev branch into master after corrections are made without losing the changes due to the revert? 更正后,如何最好地将这个dev分支重新合并到master中,而又不会由于还原而丢失更改?

On the face of it this sounds like you are using revert incorrectly in your workflow. 从表面上看,这听起来像是您在工作流程中使用了不正确的还原。

To avoid this, if master has advanced beyond a branch you should merge master into the branch rather than the other way around. 为避免这种情况,如果master已超越分支,则应将master合并到分支中,而不是相反。

So: 所以:

  • Develop in branch. 在分支中发展。
  • When development is complete and regression tests pass: 当开发完成并且回归测试通过时:
    • Merge master into branch (NOT branch to master) 将master合并到分支(不分支到master)
    • Run regression tests in branch 在分支中运行回归测试
    • Resolve any failures in the branch 解决分支中的任何故障
    • When tests pass: 测试通过时:
      • If master has changed since the merge back to master, rinse and repeat (re-merge master to branch, re-test, re-resolve). 如果从合并回母版以来母版已更改,请冲洗并重复(将母版重新合并到分支,重新测试,重新解析)。
      • Otherwise, merge branch back to master (fast-forward). 否则,将分支合并回主节点(快进)。

This workflow avoids any need to revert at any point as part of the promotion workflow (developers may still need to revert from time to time in their development branches). 此工作流避免了在促销工作流中任何时候都需要还原的情况(开发人员可能仍需要在其开发部门中不时还原)。

You should never need to revert a merge from master to a branch since for the changes to have been accepted into master they must have passed testing before they reach the master in the first place. 您永远不需要将合并从master还原到分支,因为要使更改已被接受到master中,它们必须首先通过测试才能到达master。 Therefore any failures arising from the merge into your branch are required to be resolved in that branch before they can be accepted back into master. 因此,由于合并到分支机构而引起的任何故障都必须在该分支机构中解决然后才能将其接受回master。

git won't merge any commits it already merged before. git不会合并之前已经合并的任何提交。 As the commits are still in the history of master (but were reverted by a later commit) git won't apply them again. 由于提交仍在master的历史中(但后来又被提交还原了),因此git不会再次应用它们。 The solution is either: 解决方案是:

  1. Revert the revert : Simply git revert the commit that reverted the changes. 还原还原 :简单地git revert还原变更的提交。

or (better solution): 或(更好的解决方案):

  1. Merge master into your feature branch regularly or when it is ready. 定期或在准备就绪时将master合并到功能分支中
    • If all tests pass: Fine, merge it into master (which should be a fast forward) 如果所有测试都通过:很好,将其合并到master(应该是一个快速的方法)
    • Otherwise do what you need to do to fix the issues. 否则,请执行解决此问题所需的操作。

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

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