Skip to content

Instantly share code, notes, and snippets.

@alinaselega
Created June 28, 2021 14:37
Show Gist options
  • Save alinaselega/99c876e0448220364b92a32a9467ef17 to your computer and use it in GitHub Desktop.
Save alinaselega/99c876e0448220364b92a32a9467ef17 to your computer and use it in GitHub Desktop.
How to remove the last wrong commit from history

If you accidentally pushed a wrong file to the remote, you can remove the file and the erroneous commit from the history with the following. Identify the last good commit you want to go to and copy its SHA. (Make sure you have no unsaved changes in your local repo as they will be lost.) Then do:

git reset --hard SHA_ID
git push -f

The first command resets HEAD to the commit SHA_ID. The second one force pushes the new state to the remote.

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