I'm not really familiar with how git works. I pushed a commit by mistake and want to revert it. I did a
git reset --hard HEAD~1
Beware Fellow Googlers: This does not only revert the commit, but discards all file changes!
and now the project is reverted on my machine, but not on github. If I try to push this code, I get the error 'Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.' How do I remove this commit from github?
To revert a commit with GitKraken, simply right-click on any commit from the central graph and select Revert commit from the context menu.
This article has an excellent explanation as to how to go about various scenarios (where a commit has been done as well as the push OR just a commit, before the push):
http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
From the article, the easiest command I saw to revert a previous commit by its commit id, was:
git revert dd61ab32
You can do git push --force
but be aware that you are rewriting history and anyone using the repo will have issue with this.
If you want to prevent this problem, don't use reset, but instead use git revert
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