Read the whole answer prior to doing anything, preferably make a backup of the git repo (the whole project folder) if you feel unsafe using possibly destructive commands.
If you haven't pushed your changes after the bad merge:
If you type git reflog
you should get a revision that marks your history just before the erroneous merge was made. If you don't care about any changes you may have done since that point in time (including locally committed/non committed files), I would use git reset --hard XYZ
if XYZ is the reference that you liked while reviewing git reflog
.
This will make your history look like nothing bad even took place, which I would prefer if I hadn't pushed any changes anywhere (because you don't really want to screw with other persons git history, in case they pulled from the remote that you pushed your 'bad' changes to).
If you have pushed your changes after the bad merge:
There are many hints in the official documentation located here: https://github.com/git/git/blob/master/Documentation/howto/revert-a-faulty-merge.txt (that page is linked to from man git revert
).
I recommend that you skim through most of it to find some general reasoning and find the case that you want to try out. git revert
preserves your current history and builds onto it, contrary to git reset
which let's you backtrack your history and 'erase' parts of it. If you made a backup of your git repository, you should be able to play around and learn a thing or two while at it :)