1

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?

Robert Audi
  • 8,019
  • 9
  • 45
  • 67

2 Answers2

3

You can simply do this:

repo = Grit::Repo.new(...)
repo.log('master', path_of_the_file, max_count: 1)[0].date

Hope that helps!

Pablo Fernandez heelhook
  • 11,985
  • 3
  • 21
  • 20
0

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • I thought of that, but that wouldn't work for me. What I am trying to get is the date/time of the last commit on the file not the actual modification date. – Robert Audi Feb 08 '12 at 13:18
  • It would be good if you clarified your question because you are saying commit time now, not modification time as is in the question. – the Tin Man Feb 08 '12 at 18:14
  • First of all, sorry for the late response. You are completely right, I will edit the title right now. I also found out that `git log -1 --format="%cd" -- ` gives the date of the last commit on a file. What I was trying to do, is to do the same using Grit. – Robert Audi Feb 10 '12 at 14:51