Reputation: 1537
I was working with the develop branch and made the commit.
And then, I was supposed to do a git pull origin develop
- instead I accidentally did this git pull origin master
Then, I saw this message Merge branch 'master' of repo into develop branch
Is there anyway I can undo this ?
Upvotes: 0
Views: 119
Reputation: 51333
Reset the merge commit:
git reset --hard HEAD~
and pull again
git pull origin develop
PS: I assume that your develop
branch actual points to the merge commit.
EDIT
if I do this, would I loose the commit made in develop branch ? No, right ?
The commit will not be referenced anymore, but it is still there. Git will Keep unreachable commits for a while. The default is 90 days. See git gc
The optional configuration variable gc.reflogExpire can be set to indicate how long historical entries within each branch’s reflog should remain available in this repository. The setting is expressed as a length of time, for example 90 days or 3 months. It defaults to 90 days.
So within this period you can restore the commit, but you must know it's id. You find the id in the reflog if it is not expired yet or just save it somewhere.
If you don't feel fine with this you can just create a local branch that points to the actual commit of your develop
branch before doing a git reset --hard
. In this case the local backup branch will reference the commit and git gc will not delete it (because it is referenced). E.g.
git branch backup/develop
git reset --hard HEAD~
If you think now: "Oh no I want to go back". Just do
git reset --hard backup/develop
otherwise delete the local backup branch
git branch -D backup/develop
Upvotes: 2