Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I go back to previous Git Commit?

Tags:

git

How do I go back to previous commit?

I would like my files to look exactly like all my files did when I committed the below commit.

$ git log
commit 81cf7fa47adc0923aeabe323778e2783f2e832f5
Date:   Thu Apr 2 21:32:27 2015 +1000

I looked around an so many people have different answers.

like image 920
joeyk16 Avatar asked Apr 17 '15 10:04

joeyk16


People also ask

How do you go back to previous commit and push?

If you want to test the previous commit just do git checkout <test commit hash> ; then you can test that last working version of your project. If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit.


1 Answers

You can always checkout to specific commit in git by following command

git checkout commit_hash

So in you case it will be

git checkout 81cf7fa47adc0923aeabe323778e2783f2e832f5

Or HEAD@{1} is the pointer to the one commit back so following will do the same

git checkout HEAD@{1}
like image 87
Hardik Avatar answered Oct 29 '22 16:10

Hardik