Delete Pushed Commit

Cover Image for Delete Pushed Commit

Accidently pushed commit to wrong branch ? incomplete code ? With simple command you can delete the commit pushed on the remote.

To delete the commit, you need the last commit id, up to which you want to retain the commits. You can get the comment id from the GitHub.

Grab the commit id and use it in the below command.

git reset --hard <sha1-commit-id>

Once the head is reset, you need to push the changes.

git push

This will reset the head to the last provided commit id. That’s it you can start working on your code again.

Happy coding! 😃