How do you revert a faulty git merge commit

后端 未结 2 388
走了就别回头了
走了就别回头了 2021-01-01 20:11

So one of my coworkers accidentally made a merge that actually only kept one side of the tree. So he started a merge, deleted all the changes introduced by the merge, and th

2条回答
  •  庸人自扰
    2021-01-01 21:03

    The git documentation says this about reverting merges: git/Documentation/howto/revert-a-faulty-merge.txt although this is mostly about reverting merges that brought in bad changes, rather than reverting merges that were done incorrectly.

    Basically, reverting a merge will undo the data changes, but not the history (graph) changes. Therefore it is expected that reverting your faulty merge does nothing.

    One way you can deal with this is to do the merge again, then merge the result of that into master. In your example this could be like:

    git checkout -b temp/merge-fixup ead364653b601f48159bca5cb59d6a204a426168
    git merge 2fce9bfe8f721c45ea1ed5f93176322cac60a1d9
    git checkout master
    git merge temp/merge-fixup
    git branch -d temp/merge-fixup
    

提交回复
热议问题