Reputation: 12707
In a git repository in which I switch back and forth between branches, file modification times as shown by mtime
in ruby (or the operating-system based measure of the modification time, e.g. through ls -l
) show the time I last changed branches instead of the actual time the file was modified.
I understand Git stores file modification time for all files, but how do I get the actual modification date displayed, e.g. from a ruby call?
e.g. I see I can get this from the command line:
git log -1 --format="%ad" -- path/to/file
but not sure what the best Ruby way to do this is.
Upvotes: 1
Views: 396
Reputation: 5950
I believe this is not possible; i.e. that git stores only the commit time, not the modification time. However, you might want to check out metastore, which is an addition to git that stores this metadata in a separate file.
However, since the commit time is sufficient for your purposes, you can run the command directly from ruby; something like:
%x(git log -1 --format='%ci' path/to/file)
Or you can use one of the ruby git libraries. I have never used these libraries myself, so I can't really vouch for any of them.
EDIT: Added the part about commit time, since that was sufficient for OP's purposes.
Upvotes: 2