Undo a git merge after origin pull

After not having worked on an app for a long time I started again, and couldn't sort out an error.

So I checkout out a previous local branch, fixed it and then i did this:

git checkout master
git pull origin master
git merge new_master
git push origin master

(not realizing that I was going to merge it with the previous errors)

Then I tried a few things that I found on stack overflow and now I am completely lost.

How can I backtrack from this?

I have pulled the master from github.


You can mark your current master branch (which isn't as you would like)

git branch tmp

You can reset your master to an older commit (look at the history of master on GitHub, and pick a SHA1 before your push)

git reset --hard old_SHA1

Then you can look at the history of the local tmp branch, and cherry-pick the commit(s) you want to apply to master .

Once this is done, you can force push to origin:

git push --force origin master

Try to revert it:

Find out the hash of the git merge

git checkout master git pull origin master git merge new_master git push origin master

with git log , then (Undoing Merges):

$ git revert -m 1 hash_founded

But, assuming you want to come back before the git pull , you should go for

$ git revert -m 2 hash_founded

The -m option "specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent." (git revert)

You can always reset as well: Revert to a previous Git commit

链接地址: http://www.djcxy.com/p/37820.html

上一篇: 从Github更新克隆的回购

下一篇: 原点撤消后撤消git合并