Skip to main content

How to undo an accidental git merge that has not been pushed to GitHub yet?



There are several ways to do this. You can try out one of the following commands.

1.
git reset --hard <commit_sha>
Check git log to find the commit_sha for the command above.

2.
git reset --hard HEAD~5
Five here is the number of commits that you need to get back.

3.
git reset --hard ORIG_HEAD
 ORIG_HEAD will point to a commit directly before merge has occurred. You don't need to find for the commit_sha.

Cheers. :)


Comments

Post a Comment