Remove last commit from remote git repository

Git

Git Problem Overview


> Possible Duplicate:
> Rolling back local and remote git repository by 1 commit

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]

Thanks.

Git Solutions


Solution 1 - Git

Be careful 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, most likely 'master'>

Solution 2 - Git

If nobody has pulled it, you can probably do something like

git push remote +branch^1:remotebranch

which will forcibly update the remote branch to the last but one commit of your branch.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1059540View Question on Stackoverflow
Solution 1 - GitknittlView Answer on Stackoverflow
Solution 2 - GitMichael Krelin - hackerView Answer on Stackoverflow