Unmerge in GIT with 3 branches

38 Views Asked by At

I have searched but all examples I have found only involves 2 branches. We have 3 branches

  • Master (m)
  • Develop (d)
  • Feature (f)

Where the feature branch is supposed to be merged directly into master but there is a merge from develop into the feature branch that should not be there.

                            1       2
f            *----c---------*--c----*
            /              /         \              3
m *--------*--------------/-----------*---   ------*
   \                     /                        /
d   *---------c-------c-*-----c-----------   ----*

What will happen if I revert commit 1 from develop inte feature? Will I lose parts of develop on commit 3?

To clarify #2 is not done yet there is just a PR at that stage now.

2

There are 2 best solutions below

2
eftshift0 On

Nice mess-up you dug yourself into, huh!

There is a direct later merge of develop into master so it's not like you included something in master from develop that should not be there.... in this case, if there is something real to gain, it would only be cosmetic to clean up history of your feature branch... and if you went ahead to remove that merge commit (which is possible.... by rewriting history), it would also require rewriting history of master to get it really cleaned up so.... there is no practical gain in trying to clean it up. Live with it.... unless you really really really want to rewrite history of master (which should be a show-stopper right there).

If develop were not merged into master then that would be a nice case to study.

0
TheBurnMill On

We solved it by creating a new branch, cherrypick commits from the messy branch and then ditching it.

By the way, thanks for all the suggestions.