Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git reset to previous commit

Tags:

git

I have three commits I made which I attempted to clean up some code. Anyways I managed to completely destroy what I was working on. And I want to delete the past three commits and return to a specific commit SHA1.

How can I restore to that previous commit and delete the history of those 3 commits? (The history deleting part is not a big deal). These commits are pushed already, so I am a little lost.

Thanks!

like image 663
Steven Avatar asked Mar 19 '12 02:03

Steven


People also ask

What is git reset commit?

Summary. To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.


1 Answers

Find the commit you want to reset to:

git log 

Once you have the hash:

git reset --hard <hash> 

And to push onto the remote:

git push -f <remote> <branch> 
like image 196
triad Avatar answered Oct 08 '22 13:10

triad