How to undo a merge in Git
In this tutorial, we are going to learn about how to undo a git merge to a previous commit with the help of examples.
Consider we have a two branches master,test in our repository then we added a new commit to the test branch and merged it to a master branch.
After some time we find errors in the merged branch and undoing the git merge.
Undoing git merge
-
Navigate to the merged branch inside the command line.
-
Run the
git resetcommand followed by the--hardflag andORIG_HEAD.
git reset --hard ORIG_HEADThis above command will undo the git merge to a previous commit.
Note:
ORIG_HEADis referencing to the previous commit before the merge.


