Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git inspect time at which commit was pushed [duplicate]

Tags:

git

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?

like image 252
Rich Avatar asked Jun 13 '12 10:06

Rich


2 Answers

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.

like image 57
Rich Avatar answered Sep 29 '22 16:09

Rich


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.

like image 36
Michał Politowski Avatar answered Sep 29 '22 16:09

Michał Politowski