Steve Chamaillard Steve Chamaillard - 1 year ago 77
Git Question

Rollback an old branch from master regardless of other branches pushed afterwards

First scenario :

I have 3 branches that I worked on. Branch A, branch B, branch C.

I developped, tested and merged/pushed branch A to master. I delete branch A since it's merged to master.

A week later, branches B and C are tested and pushed to master. I delete B and C since they're merged to master.

Another week later, the boss comes in the office and says "A was a bad idea, I'd like to remove this.".
Obviously, he wants to remove A, but wants to keep B and C in the production.

How can I do this ? In this scenario, A is totally independant from B and C.

Second scenario :

This scenario is the same as the first scenario, except B and C rebased to master when A was merged to master.
Thus, they received new methods available thanks to A, and used them.

Now I wonder, how could we "remove" A without breaking B and C ?

To me the answer is "tests will tell what's wrong", but we don't have tests.


Answer Source

Because your boss wants to completely remove the changes introduced into master from the A branch, you should be able to get away with simply reverting the A merge commit in master. Using git revert will introduce a new commit which effectively undoes everything which the original commit introduced.

git checkout master
git log
# find the SHA-1 hash of merge commit A (e.g. d82n93kd...)
git revert d82n93kd -m 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download