Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo the last commit on GitHub?

I want to undo the last commit pushed to GitHub on the master branch of a repository, and make it so that it's as if this commit never existed and doesn't appear in the commit history.

How do I go about this?

Note to those voting to close — the proposed alternative questions are needlessly complex, have condescending answers, and are littered with giant walls of text that are difficult to sift through.

Hence, this simple question with a simple answer for my benefit and that of posterity.

like image 690
GirkovArpa Avatar asked Jan 25 '26 23:01

GirkovArpa


1 Answers

If you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:

git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force

This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉

like image 53
GirkovArpa Avatar answered Jan 28 '26 17:01

GirkovArpa