1

I have merged master branch into my branch A last month, but then I reverted it. After that, new changes have been commited. Now I want to merge the master branch again, and I found that I couldn't merge the commits of master before "reverting" of the branch A, i.e.
Master: commit1--commit2--commit3-----commit4
                                            \                                     \
A: commit5--commit6-------merge-revert-commit7-merge
Now git has considered my revert as a new commit and don't take changes in commit1 and 2 in branch A. What can I do?

Similar questions are here:
I reverted a merge in git, now how do I redo the merge?
How do i redo commit after Revert?

1
  • 2
    The short answer is revert the revert. Please edit the question to use a code block for that branch representation, it’s not clear what it means atm Commented Oct 2, 2022 at 10:12

1 Answer 1

2

What you need to do is rewrite the branch so that git does not consider it as being merged anymore.... and your branch chart does not make clear what the branches look like.... here's one example I am creating out of thin air:

A <- B <- C <- D <- E <- I <- J <- (master) ^ / \ F <- G <- H <-- ^ \ K <- (feature) 

So.... in J, we reverted the merge done in I.... how can we then try to merge feature knowing that a part of it (or even all of it) was already merged/reverted? That will confuse git, right?

We just rewrite the branch so that git does not see the branch as being merged anymore:

 git checkout B git cherry-pick B..K git branch -d feature # set feature over here 

After this is done, we get this:

 / F' <- G' <- H' <- K' <- (feature) v A <- B <- C <- D <- E <- I <- J <- (master) ^ / \ F <- G <- H <-- 

And git will not consider any of the revisions in B..feature to be merged, so this should work:

 git checkout master git merge develop 

Which should give you:

 / F' <- G' <- H' <- K' <-------- (feature) v \ A <- B <- C <- D <- E <- I <- J <- L <- (master) ^ / \ F <- G <- H <-- 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.