tags:

views:

59

answers:

5

I'm trying to clone a git repository from a certain date. Even if this is not possible. Is it possible to clone the git repository and then roll it back to a certain date?

Example: my repository has been updated since May 2010, but I'd like to get the version from June 5th. I'd like to run the following command:

git clone [email protected]:projectfolder -date 06-05-2010
+8  A: 

Cloning the repository will give you the entire commit history of all the source code.

You need only scroll back through git log and find the desired commit on your target date. Running git checkout SHA where SHA is the commit hash will give you the state of the source code on that date.

edit:

git log --since=2010-06-05 --until=2010-06-06 will help narrow it down!

Jake Wharton
+2  A: 

You can use git's revert command to revert every commit back to the date you are looking for, or you can just create a a new branch at the commit you are interested in.

Matt Kane
+1 for branching
Chuck Vose
Reverting will abandon any newer history which is never a good option. Branching off of the commit immensely preferred to revert.
Jake Wharton
This is destructive and there's much better ways of doing it.
Daenyth
+2  A: 

Maybe something like this:

git log --since=2010-06-05 --until=2010-06-05

Find one of the commit ids you like there then do a git checkout <checkout id>

Chuck Vose
Damn. I was editing my answer to add that exact command when you answered!
Jake Wharton
hehe, happens to the best of us :)
Chuck Vose
+1  A: 

Consider the following commits:

5 May (A) -- 7 May -- master (current)
5 May (B) -- 7 May /

There is no way git can figure out whether you want commit A or B. So, you should use git log or gitk to get the SHA1 of the commit from that date you want and then git checkout it.

svick
+1  A: 
git clone [email protected]:projectfolder
git reset --hard $(git rev-list -1 $(git rev-parse --until=2010-06-06) master)
Aristotle Pagaltzis