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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With