I have a jekyll site, and I want to find the last commit date of a certain post using ruby/grit.
I know that I can do the following using git:
git log -1 --format="%cd" -- <file>
How can I do something equivalent using ruby/grit please?
I have a jekyll site, and I want to find the last commit date of a certain post using ruby/grit.
I know that I can do the following using git:
git log -1 --format="%cd" -- <file>
How can I do something equivalent using ruby/grit please?
You can simply do this:
repo = Grit::Repo.new(...)
repo.log('master', path_of_the_file, max_count: 1)[0].date
Hope that helps!
From the File documentation for mtime:
Returns the modification time for the named file as a Time object.
File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
Ruby also supports ctime
, which is when the directory information for the file was changed. On Windows ctime
is a little different behavior, because Windows supports creation times for files, unlike Linux and Mac OS.