I accidentally ran git merge some_other_branch on my local master branch. I haven’t pushed the changes to origin master. How do I undo the merge?
After merging, git status says:
# On branch master
# Your branch is ahead of ‘origin/master’ by 5 commits.
How do I undo all these commits?
git reflog check which commit is one before the merge (it will be better than glog log) Then you can reset it with: \”git reset –hard commit_sha\”.\n\nparaphrase: There\’s also a sequel: git reset –hard HEAD1 — — .\n\n1 commit. Note that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them stash changes away or see –merge option below.\n\nuse: git reset –hard ORIG_HEAD — in this direct case, as @Velmont suggested below in his answer.\n\nThis may be a good way to keep your changes. ORIG_HEAD will point to one commit before merg, so you don\’t have to look for it yourself.\n\nAnother tip is to use the –merge switch instead of –hard because it doesn\’t reset files unnecessarily: git reset –MERGE ORIG_HEAD.\n\nThe index — –merge Resets the index and updates the files in the working tree that differs between commit> and HEAD, but retains files that are different between the Index and working (i.e., which has not been added).