Here\'s what I did on my supposed-to-be-stable branch...
% git rebase master
First, rewinding head to repla
git revert
is less dangerous than some of the approaches suggested here:
prompt> git revert 35f6af6f77f116ef922e3d75bc80a4a466f92650
[master 71738a9] Revert "Issue #482 - Fixed bug."
4 files changed, 30 insertions(+), 42 deletions(-)
prompt> git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
prompt>
Replace 35f6af6f77f116ef922e3d75bc80a4a466f92650 with your own commit.
you can use the command reset
git reset --soft HEAD^1
then:
git reset <files>
git commit --amend
and
git push -f
Undo multiple commits git reset --hard 0ad5a7a6 (Just provide commit SHA1 hash)
Undo last commit
git reset --hard HEAD~1 (changes to last commit will be removed ) git reset --soft HEAD~1 (changes to last commit will be available as uncommited local modifications)
The existing answers are good and correct, however what if you need to undo the push
but:
Use this command to revert the change to the ref:
git push -f origin refs/remotes/origin/<branch>@{1}:<branch>
git push origin +7f6d03:master
This will revert your repo to mentioned commit number
If you want to ignore the last commit that you have just pushed in the remote branch: this will not remove the commit but just ignoring it by moving the git pointer to the commit one earlier, refered by HEAD^ or HEAD^1
git push origin +HEAD^:branch
But if you have already pushed this commit, and others have pulled the branch. In this case, rewriting your branch's history is undesirable and you should instead revert this commit:
git revert <SHA-1>
git push origin branch