+11 votes
1 view
in DevOps and Agile by (20k 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

+13 votes
by (28.4k 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 (30k points)
If you are not done with merging then you can abort that merge using:
git merge --abort
Welcome to Intellipaat Community. Get your technical queries answered by top developers !