Both answers are outdated. It is NOW possible to change the history.
Consider the following as an example, you have the following:
0c39034 commit you want removed
f7fde4a commit that you want to be in
DO NOT use revert as reverting will cause you to have:
e499d89 commit that supposedly reverts 0c39034
Then, you need to rebase and squash the commits that you want removed as in the following:
git rebase -i HEAD~3
pick f7fde4a commit that you want to be in
squash 0c39034 commit you want removed
squash e499d89 commit that supposedly reverts 0c39034
# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Do a git log to confirm.
git log
Push your changes:
git push --force
Doing this will totally remove 0c39034 and e499d89 in your history. They can still be accessed in web ui if (and only if) you have the complete commit-id. It will say something like:
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I want to end this by saying that what @instantepiphany said holds true as best practice and make sure never to hard-code credentials over at github.