34

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.

1

2 Answers 2

35

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^

Sign up to request clarification or add additional context in comments.

4 Comments

That will reset my local branch. Is it then just a case of pushing to update github?
You can either reset or checkout the previous commit and push that to github as head. Checkout the previous commit checkout master^
But hard reset or previous commit will need force push, right? A force push overwrites public history and requires everyone who has cloned the repo to rebase their clone.
@Siddu Sorry for getting back to you so late. Yes, you have to do a force push. git push -f.
21

To answer this more succinctly:

git checkout master git reset --hard <commit_before_merge> git push -f 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.