Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get snapshot of a git repo on a particular date

Say I have a repo with multiple banches.

Is it possible to get the repo snapshot of some particular date/time using usual git foo? (We currently have code dumps every day, and I am thinking of ways to remove that)

(Assuming no branches are permanently deleted, and the git commit history hasn't been played with)

Edit: Interim branch merges are possible.

like image 942
Anshul Goyal Avatar asked Sep 26 '13 13:09

Anshul Goyal


1 Answers

Beware of the @{<date>}, based on the reflog (meaning, limited by default to 90 days).
See "Specifying Revisions" in git rev-parse.

"git checkout by date" suggests another method:

git checkout `git rev-list -n 1 --before="2013-09-25 5:00" master`

Note this warning though:

rev-list won't work if you have any branches merged.
For example: I wanted to go back on V5 branch but ended up in V4.2 branch.

A more robust way would to add --first-parent:

git checkout `git rev-list -n 1 --first-parent --before="2013-09-25 5:00" master`
like image 114
VonC Avatar answered Sep 20 '22 19:09

VonC