Skip to content

Instantly share code, notes, and snippets.

Last active September 10, 2022 16:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

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