10

How can I tell what version was present in a git repository at a given time?

Say I have a shared repository into which several users can push changes, and I want to freeze a snapshot at 12:00 on a given day in the past.

If someone makes a local commit at 11:30, but only pushes it to the central repos at 12:30, can I detect that later on?

Can I detect if someone acting after 12:00 has doctored a local commit to have a recorded commit date of 11:30, and then pushed that upstream?

Rich
  • 15,048
  • 2
  • 66
  • 119

3 Answers3

11

Git itself doesn't track this information, but I was able to look at the file creation timestamp on the commit object file in the "objects" directory in the git repository on the server itself.

Rich
  • 15,048
  • 2
  • 66
  • 119
2

You could either use a hook, probably the post-receive hook to store the required information somewhere yourself, or simply enable the reflog (it is disabled by default in a bare repository). The reflog automatically keeps track of the local history of a branch, and eg. git reflog -1 --format=%H master@{12:00} will tell you what commit was the master ref pointing to at 12:00.

Note that the reflog expires, you can configure the expiration time with gc.reflogexpire.

Michał Politowski
  • 4,288
  • 3
  • 30
  • 41
1

git does not log when things are pushed into a repository (or fetched for that matter), only the two timestamps on the commits themselves, so I don't think there's a reliable way to do this without writing hooks that would store extra metadata somewhere for you, or relying on logging done by git-daemon, ssh, or your http server, depending on what method is used to push/fetch.

twalberg
  • 59,951
  • 11
  • 89
  • 84