I had a repo once where master
had gone off on a tangent from develop, stuff another developer did, and I
wanted to bring it back to the commit where it first forked off from develop
. Even though the remote origin
had been synced with local master
, I knew that no other developer had worked on that branch, and I could
safely revert. So just say the commit I wanted to revert to was 56b33e4
:
# make sure we are on master
$ git checkout master
# reset local branch HEAD back to desired commit
$ git reset --hard 56b33e4
# force remote "master" to point to same commit
$ git push origin +56b33e4:master
# remove unwanted origin/HEAD branch (which was pointing to origin/master)
$ git remote set-head origin -d
Some handy links:
https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit https://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit https://stackoverflow.com/questions/354312/why-is-origin-head-shown-when-running-git-branch-r