tags:

views:

4028

answers:

3

I "accidentally" pushed a commit to github.

Is it possible to remove this commit?

I want to revert my github repository as it was before this commit.

+19  A: 

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~1 and delete the first line.

Then, force push using git push origin +master.

See http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html#_8230_and_then_some for more information.

Oh, and if your working tree is dirty, you might want to do a git stash first, and a git stash apply after.

Can Berk Güder
More accurately, you /have/ to stash because git rebase -i won't let you if you have a dirty tree.
Otto
No local tree modification is necessary at all to satisfy the users's request.
Dustin
A: 

you probably want to check out http://stackoverflow.com/questions/443896/removing-code-from-github

Henrik Paul
The link you've given is for removing directories, this question is about reverting commits on Github.
Abizern
+23  A: 
git push -f origin HEAD^:master

That should "undo" the push.

Dustin
This worked fine too! It removes the push from github but leaves my local repository intact. Thanks!
hectorsq
Well, yes. It only does what you asked for. :) Your repository and the remote repository don't have to have matching refs.
Dustin