36

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?

skiphoppy
  • 97,646
  • 72
  • 174
  • 218

2 Answers2

45
git checkout @{two.days.ago}
Robie Basak
  • 6,492
  • 2
  • 30
  • 34
  • 7
    Note that this command would checkout what you had checked out in **your** repository two days ago; it is local repository only information. See "Specifying revisions" section in [`git rev-parse`](http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html) documentation; it uses *reflog* – Jakub Narębski Oct 30 '10 at 08:44
26

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.

ahaurat
  • 3,947
  • 4
  • 27
  • 22