Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undo last git commit that is pushed to origin

Tags:

git

git-commit

I have committed wrong files to my branch and pushed it to origin. I have seen the article at How to undo last commit(s) in Git? that deals with undoing a local commit, but my problem is that I have pushed the commit to origin. How to undo this?

like image 917
akonsu Avatar asked Jul 10 '13 03:07

akonsu


2 Answers

git reset HEAD^
git push origin +HEAD

should work for you. See the git-push and git-reset documentation for more information on why.

like image 167
Matt Bryant Avatar answered Sep 22 '22 09:09

Matt Bryant


Since you've already pushed to origin, your change has been published for others to see and pull from. Because of this, you probably do not want to rewrite the history. So the best command to use is git revert.

This creates a new commit that reverses the changes you made. Push the new commit and origin will be fixed.

Here is an SO answer that gives more details on this.

like image 42
gtrig Avatar answered Sep 26 '22 09:09

gtrig