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 reset
command followed by the--hard
flag andORIG_HEAD
.
git reset --hard ORIG_HEAD
This above command will undo the git merge
to a previous commit.
Note:
ORIG_HEAD
is referencing to the previous commit before the merge.