IskandarG IskandarG - 1 year ago 107
Git Question

Undo a git merge that has been pushed and redo the merge

I had some local commits and there were changes made on master. So I did a:

git pull // it automatically merged and had a conflict with one file only.
subl <file> // Made the wrong fix and saved it
git commit // It opened nano and I Typed "fixed merge" saved it
git push master origin

How do I go back to before the pull and redo the merge and push? Especially get back to right before the merge.

Answer Source

You can revert that merge with:

git revert -m 1 (Commit id of the merge commit)

More informations can be found in Official GUIDE

And you can do it in other way by using git reflog <branch> to find out where your branch was before the merge, and git reset --hard <commit_id> to restore the old revision (you will get back to this commit). Then just you can push it back.

Reflog will show you older states of the branch, so you can return it to any change set you like.

Make sure you are in correct branch

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download