Note: please see an alternative to git rebase -i
in the comments below—
git reset --soft HEAD^
First, remove the commit on your local repository. You can do this using git rebase -i
. For example, if it's your last commit, you can do git rebase -i HEAD~2
and delete the second line within the editor window that pops up.
Then, force push to GitHub by using git push origin +branchName --force
See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).
Oh, and if your working tree is dirty, you have to do a git stash
first, and then a git stash apply
after.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…