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!
Summary. To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.
Find the commit you want to reset to:
git log
Once you have the hash:
git reset --hard <hash>
And to push onto the remote:
git push -f <remote> <branch>
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