Janik von Rotz


1 min read

Undo a pushed git merge

First of all the solution to the problem I am tackling should not exist in the first place. If you have to revert a merge on a git branch, think about alternatives. If not other option is left, I’ll show you how you can undo a merge with git revert.

First checkout your branch that has been targeted by the merge.

git checkout master

Have a look into the git log and look for the hash of the merge commit.

git log

Now undo the merge using the revert command.

git revert -m 1 COMMIT_HASH

As mentioned undoing is a dangerous process. Depending on how far the merge commit is from the head of your branch you end up with a lot of conflicts.

Check the git repo for conflicts.

git status

Once you have resolved the issues you can commit the revert commit.

git commit

Congrats! You did something were bad 😠

Categories: Software development
Tags: git
Improve this page
Show statistic for this page