How to undo a git merge?

You can undo or revert an unintended merge in your local git repository before it’s pushed to remote repository using git reset –hard command.


Create a new local git repository:

Create your first git commit on the default branch:

Create a new branch:

Create your second commit on the feature branch:

Merge and delete the feature branch:

Check files in the master branch:

Revert/Undo a git merge that is not already pushed:

Note: 1 in HEAD~1 represent last commit. If any other commits happen in-between, use git reset –hard <merge_commit_sha> instead which you can get using git log command.

Check files in the master branch: