Git · Middle · Question 11 of 75
How do you undo a merge commit that was already pushed to main?
- 1
git reset --hardto before the merge and force-push - 2
git cherry-pick --undo <merge>on top ofmain - ✓Correct answer:
git revert -m 1 <merge>to undo it relative to the first parent
Explanation
A merge has two parents, so revert needs -m to know which side is the mainline. Note that re-merging the same branch later won't bring the reverted changes back unless you revert the revert.