Skip to content

Instantly share code, notes, and snippets.

@yavuztas
Created June 13, 2017 11:27
Show Gist options
  • Save yavuztas/e988791344fc40b35523a09a4d874853 to your computer and use it in GitHub Desktop.
Save yavuztas/e988791344fc40b35523a09a4d874853 to your computer and use it in GitHub Desktop.
Git undo a branch merge
With git log check which commit is one prior the merge. Then you can reset it using:
git reset --hard commit_sha
There's also another way
git reset --hard HEAD~1
will get you back 1 commit.
Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state.
To keep them either stash changes away or see --merge option below.
Another way:
git reset --hard ORIG_HEAD
might yield better results, as it should preserve your changes.
ORIG_HEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself.
A tips is to use the --merge switch instead of --hard, it doesn't reset files unnecessarily:
--merge
Resets the index and updates the files in the working tree that are different between <commit> and HEAD,
but keeps those which are different between the index and working tree (i.e. which have changes which have not been added).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment