How do i delete the last 3 commits?

use can use git reset for that

git reset --hard HEAD~3

git push --force origin master

where HEAD~3 means go back 3 commits

You can also use the commit number instead of 3 commits, so that you are sure where you are going back in time, like

git reset --hard 8315cd7962c902d39160fcf2fd018f249e7cf744

EDIT:

When rewriting history, prefer using

git push origin +master

To be safe if you are ever pushing more than one branch. You can read more at Git Force push syntax, “-f” versus “+branch”

(kudor to Josef Kufner comment pointing it out)

EDIT 2:

I just noticed that your log is printing colors as codes, So

git reset -- hard 33m8315cd7962c902d39160fcf2fd018f249e7cf744 

will not work, [[33m and [[m are color codes! So your commit number is actually 8315cd7962c902d39160fcf2fd018f249e7cf744

If you do

git reset --hard 8315cd7962c902d39160fcf2fd018f249e7cf744

it should work as well.

(Fixed the commit code on previous examples as well)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)