Sergiy Byelozyorov Sergiy Byelozyorov - 6 months ago 21
Git Question

Git: how to revert a branch merge without overwriting history?

I have two branches:

. I recently finished implementation (or at least I thought so) of
branch and decided to merge it into

git checkout master
git merge opengl
git push

After I did this, several developers who are working on the
branch pulled my changes and it turned out that my implementation conflicted with some of their code. Therefore I would like to revert the merge operation on the
branch, but without overwriting history.

Note that I would like to be able to merge the
branch into
eventually (after I fix all the bugs). Therefore simply checking out older version of
and committing it will not work - newly created commit will cancel my changes from
when I will try to merge it.

Thank you.


The documentation "How to revert a faulty merge" mentioned by cebewee explains why a git revert is tricky when reverting a merge.

So the merge will still exist, and it will still be seen as joining the two branches together, and future merges will see that merge as the last shared state - and the revert that reverted the merge brought in will not affect that at all.
If you think of "revert" as "undo", then you're going to always miss this part of reverts.
Yes, it undoes the data, but no, it doesn't undo history.

git revert is the right solution here, but it will have a consequence in the future, when you want to merge that branch again.
The next merge will then have to "revert the revert" first, and then merge the branch.