Back

Explore Courses Blog Tutorials Interview Questions
+9 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

Within my master branch, I did a git merge some-other-branch locally, but never pushed the changes to origin master. I didn't mean to merge, so I'd like to undo it. When doing a git status after my merge, I was getting this message:

# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.

Based upon some instructions I found, I tried running

git revert HEAD -m 1

but now I'm getting this message with git status:

# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.

I don't want my branch to be ahead by any number of commits. How do I get back to that point?

1 Answer

+11 votes
by (27.5k points)
edited by

Run the following command: 

git reset --merge ORIG_HEAD

The reference ORIG_HEAD will point to the original commit from before the merge.

Here, in the command mentioned above, --merge option has nothing to do with the merge. It is almost like git reset --hard ORIG_HEAD command, but safer since it doesn't touch uncommitted changes.

For more information please go through the following tutorial to get more info about git:

 

by (29.3k points)
If you are not done with merging then you can abort that merge using:
git merge --abort

Related questions

Browse Categories

...