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

如何使用Python获取GitLab仓库的最后提交日期?

获取GitLab仓库最后提交日期(Python实现)

你已经完成了认证和项目获取,接下来可以通过以下步骤获取仓库的最后提交日期:

  • 调用project.commits.list()方法,指定per_page=1只获取最新的一条提交记录
  • 从返回的提交对象中提取committed_date属性,该属性为datetime类型,可直接使用或格式化为字符串

示例代码:

# 获取最新提交记录
latest_commit = project.commits.list(per_page=1)[0]
# 提取最后提交日期
last_commit_date = latest_commit.committed_date
# 输出结果,如需格式化可使用strftime方法
print(f"最后提交日期:{last_commit_date}")
# 格式化为指定字符串(示例:2024-05-20 14:30:00)
formatted_date = last_commit_date.strftime('%Y-%m-%d %H:%M:%S')
print(f"格式化后的提交日期:{formatted_date}")

内容的提问来源于stack exchange,提问作者Lars Kager

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 11:03:20