Take the 2-minute tour ×

I have a repository I clone (or at least, I'm told to clone) using

git clone git://therepository --recursive

The repository has submodules in it. What I want to do is to get the files from the repository for a certain date. I try to do that with:

git checkout `git rev-list -n 1 --before="2011-12-10 13:37" master`

But that doesn't seem to do anything to the submodules.

Can anyone suggest how I should be doing it in order to effect the submodules? (I don't actually need a complete clone of the repository, so if there's a way to recursively fetch a particular revision through the submodules that would be fine too).


If I add the -b switch to the checkout, I can then run:

git submodule sync
git submodule update

without getting any errors, but the submodules still seem to contain the HEAD version of their files.

share|improve this question
add comment

2 Answers

Did you run git submodule update after the checkout/clone?

share|improve this answer
If I do that, I get a mixture of: 'Unable to checkout <sha>', 'fatal: reference is not a tree <sha>' and 'Please commit your changes or stash them before you can switch branches'. –  pjcard Apr 15 '12 at 5:29
add comment
up vote 0 down vote accepted

The small script here: http://cemerick.com/2009/09/28/working-with-git-submodules-recursively/

Gave me an alternative method of recursively calling checkout on each submodule (and each submodule's submodules, ad infinitum), it didn't work for me (seemed to grab the wrong revision of some files), but that might be an issue specific to myself, so perhaps it will work for others searching for the same functionality.

Please note, I had to change master for HEAD in the call to checkout, it's just a guess so perhaps it's also why I was still having issues with which revisions of files it was checking out.

I'm surprised this is seemingly both hard and rarely done (Can't find any reference to how to do it via Google). I would have thought getting a files from a specific date, or tag, for a module and submodules would have been something that people did fairly regularly, to debug old builds of code e.t.c.

share|improve this answer
add comment

Your Answer


