9

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?

Community
  • 1
  • 1
akonsu
  • 28,824
  • 33
  • 119
  • 194

2 Answers2

14
git reset HEAD^
git push origin +HEAD

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

Matt Bryant
  • 4,841
  • 4
  • 31
  • 46
9

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.

Community
  • 1
  • 1
gtrig
  • 12,550
  • 5
  • 28
  • 36
  • Is it okay, if we can just delete the branch from the origin whole together? (It was an entire new branch and I didn't want to push in the origin) – Shad Jan 06 '23 at 04:13