Skip to content

Instantly share code, notes, and snippets.

@fnavalca
Last active January 20, 2020 14:14
Show Gist options
  • Save fnavalca/4c3078ad3ef9c6f24f66caa715343d13 to your computer and use it in GitHub Desktop.
Save fnavalca/4c3078ad3ef9c6f24f66caa715343d13 to your computer and use it in GitHub Desktop.
Delete a commit in Git: local and remote

Deleting commit

Delete a local commit

If it is the last commit you do you can do it with:

git reset --hard HEAD~

If it is one of the last commits in the same branch you can do it with:

git reset --hard HEAD~2

And so on depending on what commit you want to delete.

Delete a remote commit

You must to delete first locally and then execute:

git push origin +BRANCH_YOU_WANT_TO_RESTORE_THE_COMMIT

Sources: adrian.ancona's website and stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment