by Sai gowtham

How to undo a merge in Git

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

  1. Navigate to the merged branch inside the command line.
  2. Run the git reset command followed by the --hard flag and ORIG_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.

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
26,545 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
221,520 students enrolled
44 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
114,575 students enrolled
21 hours of video content
View Course