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.
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.
Note: please see an alternative to
git rebase -iin 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.
Delete the most recent commit, keeping the work you've done:
git reset --soft HEAD~1
Delete the most recent commit, destroying the work you've done:
git reset --hard HEAD~1
For GitHub
if you want to remove do interactive rebase,
git rebase -i HEAD~4
4 represents total number of commits to display count your commit andchange it accordingly
and delete commit you want from list...
save changes by Ctrl+X(ubuntu) or :wq(centos)
2nd method, do revert,
git revert 29f4a2 #your commit ID
this will revert specific commit
In GitHub Desktop you can just right click the commit and revert it, which will create a new commit that undoes the changes.
The accidental commit will still be in your history (which may be an issue if, for instance, you've accidentally commited an API key or password) but the code will be reverted.
This is the simplest and easiest option, the accepted answer is more comprehensive.