I have been working in PhpStorm on a dedicated branch, but when pushing to github, I inadvertently merged to the master branch.
How would I undo the merge both in github and locally? The github master is used to migrate code to various servers so I need to rollback to the previous commit prior to the merge rather than create a new commit with my changes undone.
You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.
You need to reset the head to the commit just before your current head.
git reset --hard <commit_before_merge>
E.g. git reset --hard master^
To answer this more succinctly:
git checkout master
git reset --hard <commit_before_merge>
git push -f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With