revert git pull from selected branch
I am very new with git and not able to find the exact solution from google or stackoverflow. I tried Undo git pull, how to bring repos to old state well, but no success.
I have basically "initial"
and "pre_dev"
branch. Generally I merge my initial branch code into pre_dev branch.
But today I pulled pre_dev
into initial
by mistake. Now source tree is showing push notification into initial. So please let me know how to revert this. So that I don't need to push these changes.
I can see in source tree after so many tries:
I don't want this to push into initial. So please help me in this. And sorry for asking this question again, if already resolved by someone into any other stackoverflow question. Please help me as a beginner. Thanks
If you want to get rid of all the commits of pre_dev
from initial
which I assume are accidentally done, then you can easily do it using git reset, as follows:
git reset --hard origin/initial
Important Note: You will also loose all your changes (if any) from initial
branch which you have done before pulling from pre_dev
.
Generally you want to use git reset --hard
to move the branch pointer back to where it was. As Arpit notes, this might be origin/initial
; but if you have un-pushed changes that you want to keep on initial
(apart from the unintentional merge that you want to discard) then you would want something else.
By default a pull would create a single merge commit on the current branch. So in that case you could
git reset --hard HEAD^
IF the pull did something else, it might be easier to use the reflog.
git reflog initial
will show you where your initial
ref has recently pointed; identify the commit that represents the desired state of initial
. This would likely be the most recent prior commit in the list, which would mean
git reset --hard initial@{1}
链接地址: http://www.djcxy.com/p/94792.html
上一篇: 潜在的Git / Rails灾难:Web页面不再加载
下一篇: 从选定的分支恢复Git拉