Warning: This can be really bad to do. It changes your git history, which is bad and could affect other remotes. Don't do this to a project that other people are using too. Now that you've been warned, here's how to do some bad things to your repo. Do it quickly before anyone notices.
Roll back 1 commit locally:
git reset --hard HEAD~1
Roll back 6 commits locally:
git reset --hard HEAD~6
Push the rollbacks to the remote master branch:
git push origin master --force
All traces of the commit are now gone!
I know this gist is 5 years old, but in case anyone else comes across it, this is false:
This doesn't remove the commit from the GitHub reflog (e.g., https://github.com/$USER/$PROJECT/$COMMIT_ID) or from your local cache.
See this article for recovering commits from GitHub's reflog.
If you have sensitive data you want to expunge from your repo, you'll want to reference these steps instead. However, you should really rotate your credentials and think about reassessing how files make it into your git repos (e.g., consider adding a
.gitignore
file and usegit add -i && git commit
instead ofgit commit -am "Message"
).