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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With