Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check out what was in my git repository N days ago?

Tags:

git

I have to check out my source code from two days ago. Whenever I have to do this, I have to look up the syntax. It's not in the git-checkout page. I'd like to have a convenient Stack Overflow question to refer to so I don't have to look it up every time. If this has already been asked, please point me to the dupe. :)

How do I check out my source code in git from two (or N) days ago?

like image 739
skiphoppy Avatar asked Oct 29 '10 14:10

skiphoppy


People also ask

How do I see my git history?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

How do you check the state of your local git repository since your last?

Use the git status command, to check the current state of the repository.


2 Answers

git checkout @{two.days.ago} 
like image 64
Robie Basak Avatar answered Sep 20 '22 23:09

Robie Basak


All of these work (because git is pretty smart):

git checkout @{yesterday} git checkout @{2.days.ago} git checkout @{'2 days ago'} git checkout @{'5 minutes ago'} git checkout @{'1 month 2 weeks 3 days 1 hour 1 second ago'} git checkout any-branch-name@{'1 hour ago'} 

As @Jakub Narębski noted in his comment, these are references to your local repository at that time. More info in the Specifying Revisions section of the git rev-parse docs here.

like image 43
ahaurat Avatar answered Sep 19 '22 23:09

ahaurat