I commited few changes, and made a push to remote branch in github. But then I realized that I did some mistakes in the commit, and pushed lot of wrong files. Is there a way to revert the push?
-
You may be able to back out of a revision. Or at the least, update to a previous revision, correct the changes and re commit it – Kai Qing Nov 07 '13 at 01:57
-
You might take a look at this post [How to reverse a commit.](http://stackoverflow.com/questions/1809484/git-how-to-reverse-merge-a-commit) . – David Maust Nov 07 '13 at 02:02
-
[How can I remove a commit on github?](http://stackoverflow.com/questions/448919) – Rafa Viotti Nov 07 '13 at 02:30
2 Answers
The git revert
command does not rewrite history, but does take away the changes from a commit with a new commit. Then all you would have to do is to push again. This is the suggested method.
If you really want to make github look like a particular commit never really happened, there is a way, but use caution (especially if other users contribute to the github repository). In fact if others use this github repository, stop now and use the method mentioned in the first paragraph.
If this is your own private github repository and the last push is what you need to take away (assumes you are still on the same local branch):
git reset --hard HEAD~
git push -f
If it is not the last push, see man pages for either git cherry-pick
, or git rebase
to get your local directory to match what you want github to look like before doing the git push -f
. If you do not supply the -f
option to git push
, you will not rewrite history. And any push will fail if it attempts to rewrite history. The -f
option should not be used by default.

- 8,567
- 3
- 28
- 32
-
2One thing to note about this method: although this removes the commit from the GitHub commits list, it does NOT appear to delete it entirely. As long as you have the GitHub URL referencing the specific commit, you can still access it even after it's been "deleted." – jayp Aug 28 '18 at 03:16
-
See also https://help.github.com/articles/removing-sensitive-data-from-a-repository/ re deleting "private" commits – Rodney Jan 14 '19 at 11:10
Keep in mind that once you have pushed your commits to a remote repository that you should exercise caution, especially so if you have some intention of rewriting history (i.e. removing all your undesired commits by rebasing).
If you do not care about history, then reverting your bad changes can be done by using git revert
and passing it the commit identifiers you want to undo.
For example, if you have changes contained in two commits, A and B, you would like to remove:
git revert A B
This will revert commits A and B, creating a commit for each.
By default, Git will create additional commits on top of HEAD to illustrate changes being reverted. Check out the manual page for git revert
on further details on how to use it.
After making the reverts you need, simply push up again!

- 3,624
- 2
- 28
- 38