Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

How can I remove the last commit from a remote GIT repository such as I don't see it anymore 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]

1 Answer

0 votes
by (50.2k points)

Warning: If you have already fetch/pulled/cloned from the remote repository then this command will create a new remote.

git reset HEAD^ # remove commit locally

git push origin +HEAD # force-push the new HEAD commit

If you need that repo on the local system and all you need is to remove from remote then use this command:

git push origin +HEAD^:<name of your branch, most likely 'master'>

Thus, you remove commit from the remote git repository.

Refer: https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undocommitspermanently 

Browse Categories

...