If you are doing this because you have sensitive data in a commit, using the other answers here is not safe (excepting subutux's, which I'll expand on).
The github guide on this recommends using a external tool, but I prefer using the built-in one.
Firstly, make a backup of your repository. Then:
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA' \
--prune-empty --tag-name-filter cat -- --all
After this, make sure the repository is in the state you want. You might want to diff against the backup.
If you're sure it's correct, then:
#get rid of old unreferenced commits (including the data you want to remove)
git gc --prune=now
git push origin --force --all
You might want to keep the local backup for a while, just in case.