如何使用 ruby​​/grit 获取文件的最后提交日期?

发布于 2025-01-03 14:55:01 字数 185 浏览 4 评论 0原文

我有一个 jekyll 网站,我想使用 ruby​​/grit 查找某个帖子的最后提交日期。

我知道我可以使用 git 执行以下操作:

git log -1 --format="%cd" -- <file>

请问如何使用 ruby​​/grit 执行等效操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你如我软肋 2025-01-10 14:55:01

您可以简单地这样做:

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

希望有帮助!

You can simply do this:

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

Hope that helps!

假情假意假温柔 2025-01-10 14:55:01

来自 mtime 的文件文档:

以 Time 对象的形式返回指定文件的修改时间。

File.mtime("testfile")   #=> Tue Apr 08 12:58:04 CDT 2003

Ruby 还支持 ctime,这是文件的目录信息被更改的时间。在 Windows 上,ctime 的行为略有不同,因为 Windows 支持文件的创建时间,这与 Linux 和 Mac OS 不同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文