I have three commits I made which I attempted to clean up some code. Anyways I managed to completely destroy what I was working on. And I want to delete the past three commits and return to a specific commit SHA1.
How can I restore to that previous commit and delete the history of those 3 commits? (The history deleting part is not a big deal). These commits are pushed already, so I am a little lost.
Thanks!
Since your commits are pushed remotely you need to remove them. I’ll assume your branch is
masterand it’s pushed overorigin.You first need to remove
masterfromorigin:git push origin :master(note the colon)Then you need to get
masterto the status you want, I’ll assume the commit hash isABCDE:git reset --hard ABCDELastly, push
masteragain:git push origin masterThat’s it! Note that if someone already downloaded your changes from
originthis will screw them pretty much leaving their local repos unstable.