3

I just did git pull origin branch accidentally and now I have all these changes merged into master

I tried reverting the commit w/ github for mac and got this error:

fatal: Commit d0fbfb0f7d3ea8.. is a merge but no -m option was given.

2 Answers 2

6

Assuming you have not committed anything on top, git reset --hard HEAD^ will do what you want. HEAD^ refers to the first parent of the current commit, which is the one you want to reset back to.

A "hard reset" will set the current branch and the work tree to point to whatever you tell it to, discarding anything else (notably uncommitted changes). This is a BIG hammer, so be careful.

1
  • will HEAD^ work? the branch i merged had multiple commits, so i need to go like 10 commits back to get to where i was before..
    – Tom Lehman
    Commented Jan 20, 2012 at 23:52
1

You can do:

git reset --hard ORIG_HEAD

After a pull ( merge), ORIG_HEAD will point to the previous HEAD.

Not the answer you're looking for? Browse other questions tagged or ask your own question.