This shell command should do what you want:
git show "<branch>@{<timestamp>}:<path/to/file>"
For example:
git show "master@{yesterday}:some/file/in/repo"
git show "master@{2014-01-01 00:00:00}:another/file"
This prints to STDOUT
.
To run this from an arbitrary directory, you can use the -C
option to point to your repository root:
git -C path_to_my_repository show "master@{2014-05-05 12:00:00}:path_to_file"
You can run this from Python using the subprocess
module like this, or something close to it:
from subprocess import Popen, PIPE
p = Popen(['git', '-C', path_to_my_repository, 'show',
'master@{' + date_string + '}:' + path_to_file],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
# Content will be in `output`
output, err = p.communicate()
or using any other method to call a shell command. You should also be able to use libgit2, or a number of other tools.