Git remembers where your branch was before risky commands like merge, rebase and reset. It writes that commit to ORIG_HEAD, and that’s your way back.
git reset --hard ORIG_HEAD
Right after a merge that went wrong, this puts the branch back on the commit you had before, as if the merge never happened. The same works right after git rebase, git pull or git reset. Check where it points first:
git log -1 --oneline ORIG_HEAD
I find it easier than digging through git reflog for the right entry, as long as you notice the problem straight away.
Two serious warnings. First, --hard throws away all uncommitted changes in your working tree, with no undo. Commit or stash anything you want to keep before running it. Second, ORIG_HEAD only holds the state before the last of those commands. Run another merge, rebase or reset and it points somewhere else. If you’re not sure, use the reflog instead, where every step has its own entry.
Also, this only fixes your local branch. If you already pushed the merge, resetting means force pushing, and on a shared branch git revert -m 1 is the friendlier way to undo it.
Further reading: git-reset documentation, gitrevisions documentation