Skip to content

Instantly share code, notes, and snippets.

@kimw
Created February 13, 2017 01:11
Show Gist options
  • Save kimw/7c0fc91312cf961ceba877bd6086926c to your computer and use it in GitHub Desktop.
Save kimw/7c0fc91312cf961ceba877bd6086926c to your computer and use it in GitHub Desktop.
How can I remove a commit on GitHub?

Q: How can I remove a commit on GitHub?

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.

A:

Note: please see 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

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.


url: https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment