I have pushed some changes to the repository.
I want to delete the last commit from the repository and permanently remove the history entry as well.
How can I do this?
Try:
git checkout <branch> // replace branch with a name of the branch you worked on
git reset --hard HEAD~1 // this command removes the latest commit
git push --force-with-lease origin <branch> // push the changes to the remote
If nobody modified the remote while doing the operation above your push will be accepted, otherwise it may be rejected. Further steps are dependant on if you can use -f
instead of --force-with-lease
. If so do it, but it will overwrite other's changes. If not - it can't be done without changing the history.
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