【问题标题】:How to retrieve git commit history for specific time period with cURL?如何使用 cURL 检索特定时间段的 git 提交历史记录?
【发布时间】:2016-12-02 16:18:29
【问题描述】:

我正在尝试以 JSON 格式检索提交历史记录并在 txt 文件中输出。

curl https://api.github.com/repos/username/repo/commits > commitHistory.txt

通过上面的 curl 推荐,我只得到了提交历史的第一页。我想检索完整的提交历史记录,或者在执行此操作时设置日期范围。我该怎么做?

【问题讨论】:

  • 有什么原因不能克隆存储库而只能克隆git log remotes/branch?如果您尝试编写此脚本,查看parsing JSON with UNIX tools 可能会有所帮助。

标签: json git curl github github-api


【解决方案1】:

您可以使用sinceuntil 参数仅获取特定时间段的提交:

curl https://api.github.com/repos/username/repo/commits?since=2016-11-01T00:00:00Z&until=2016-11-01T23:59:59Z

详情请见api doc

【讨论】:

  • 我需要同样的 curl https://api.github.com/repos/username/repo/events 相同的命令不起作用
【解决方案2】:

对于大型结果集,来自 GitHub 的 API 请求会自动分页,因此您需要检查 Link: 标头并在有更多结果时发出更多请求。 API documentation 提供更多信息:

返回多个项目的请求默认分页为 30 个项目。您可以使用?page 参数指定更多页面。对于某些资源,您还可以使用 ?per_page 参数将自定义页面大小设置为最大 100。请注意,由于技术原因,并非所有端点都尊重?per_page 参数,例如,请参阅events

curl 'https://api.github.com/user/repos?page=2&per_page=100'

请注意,页码是从 1 开始的,省略 ?page 参数将返回第一页。

有关分页的更多信息,请查看我们在Traversing with Pagination 上的指南。

您也可以使用像 github3.py(或等效的)这样的 Python 库来执行此操作,它会为您处理分页。

就具体日期范围而言,philipjkim's answer 是正确的:使用sinceuntil 参数。

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 1970-01-01
    • 2022-01-10
    • 2013-09-20
    • 2021-09-14
    • 2011-02-25
    • 2012-04-06
    • 2018-11-01
    • 2021-08-16
    相关资源
    最近更新 更多