Skip to content

Instantly share code, notes, and snippets.

@odan
Last active September 10, 2022 16:43
Show Gist options
  • Save odan/f9e1a9aaa9b812abf3d117e88a39f128 to your computer and use it in GitHub Desktop.
Save odan/f9e1a9aaa9b812abf3d117e88a39f128 to your computer and use it in GitHub Desktop.

Removing a Commit From Github

If you accidentally committed something you shouldn’t have, and pushed it to Github, there are still ways to delete or modify it.

You can do an interactive rebase, which is useful if the commit isn’t the most recent one. If the commit was, for example, 12 commits ago, you can rebase from then, remove the offending commit, and save.

git rebase -i HEAD~12

A list with the commits will be displayed in an editor. On each line replace pick with drop to remove the commit from the history. Press Ctrl+C to exit. Then enter :wq to save the changes.

Once your local repo is in working order, you can force push to Github.

git push origin master --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment