Remove last commit from remote Git repository

Question

How can I remove the last commit from a remote Git repository such as I don't see it any more in the log?

If for example git log gives me the following commit history

A->B->C->D[HEAD, ORIGIN]

how can I go to

A->B->C[HEAD,ORIGIN]

Answer

Be aware that this will create an "alternate reality" for people who have already fetch/pulled/cloned from the remote repository. But in fact, it's quite simple:

git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit

If you want to still have it in your local repository and only remove it from the remote, then you can use:

git push origin +HEAD^:$name_of_your_branch # e.g. +HEAD^:master

Some shells interpret the ^ character. For those shells, either quote/escape or use ~:

HEAD\^
'HEAD^'
HEAD~

How to search through all Git and Mercurial commits in the repository for a certain string?

How can I split up a Git commit buried in history?