You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub v3 API获取仓库文件的最后更新时间?

获取GitHub文件最后更新时间的API方法

Great question! You can absolutely retrieve the last updated time of a file using the GitHub v3 API, and there are two simple, reliable approaches depending on what you need:

1. 直接利用你当前调用的Contents接口

The /repos/{Owner}/{Repository}/contents/{Folder/File} endpoint you're already using actually includes commit metadata for each file—no extra API calls needed.

  • If you're fetching a single file: The JSON response will contain a commit object. Inside that, commit.committer.date gives you the UTC timestamp of the last commit that modified the file.
  • If you're fetching a folder list: Each file entry in the response array will also have this commit object, so you can pull the last updated time directly from each item.

Here's a snippet of what that relevant part of the response looks like:

{
  "name": "example.txt",
  "sha": "a1b2c3d4e5f6...",
  // Other fields...
  "commit": {
    "committer": {
      "name": "Jane Doe",
      "email": "jane@example.com",
      "date": "2024-05-20T14:30:00Z"
    }
  }
}

2. 用Commits接口获取最新提交详情

If you need more context about the last update (like the commit message, author, or full commit history), you can target the Commits API directly.

Call the endpoint GET /repos/{Owner}/{Repository}/commits with two query parameters:

  • path: The relative path to your file (e.g., docs/README.md)
  • per_page=1: To only fetch the most recent commit

The response's first entry will have the same commit.committer.date field with the last updated time, plus all the full commit details you might want.

All timestamps returned are in ISO 8601 UTC format, so you can convert them to your local timezone if needed.

内容的提问来源于stack exchange,提问作者Nicke Manarin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:30:04