BKK
BKK

Reputation: 2073

Git Merge Branch Revert Workflow

Here's our Scenario:

Developers fork off Master into a new Branch and develop some code. Master progresses. When it passes QA, and gets merged into Master, a complete regression test is run. 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. How best to re-merge this dev branch into master after corrections are made without losing the changes due to the revert?

Upvotes: 0

Views: 234

Answers (2)

Deltics
Deltics

Reputation: 23056

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.

So:

  • Develop in branch.
  • When development is complete and regression tests pass:
    • Merge master into branch (NOT branch to 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. 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.

Upvotes: 1

TimWolla
TimWolla

Reputation: 32731

git won't merge any commits it already merged before. As the commits are still in the history of master (but were reverted by a later commit) git won't apply them again. The solution is either:

  1. Revert the revert: Simply git revert the commit that reverted the changes.

or (better solution):

  1. Merge master into your feature branch regularly or when it is ready.
    • If all tests pass: Fine, merge it into master (which should be a fast forward)
    • Otherwise do what you need to do to fix the issues.

Upvotes: 0

Related Questions