我如何从GitHub API获取最后一次提交 [英] How can I get last commit from GitHub API

查看:263
本文介绍了我如何从GitHub API获取最后一次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种方法是使用GitHub API(Rest API v3)从git存储库获取最新提交信息的最佳方法.

Which is the best way to get the latest commit information from a git repository using GitHub API (Rest API v3).

选项1:GET /repos/:owner/:repo/commits/master
我可以假设响应的对象"commit"是分支主服务器的最新提交吗?

Option 1: GET /repos/:owner/:repo/commits/master
Can I assume that the object 'commit' of the response is the latest commit from branch master?

选项2:GET /repos/:owner/:repo/git/commits/5a2ff
或进行两次调用,一个通过从master获取HEAD ref来获取sha,然后使用返回的sha获取提交信息.

Option 2: GET /repos/:owner/:repo/git/commits/5a2ff
Or make two calls, one to get the sha by getting the HEAD ref from master and then get the commit information using the sha returned.

推荐答案

这取决于您对"last"的定义.

It depends on your definition of "last".

  • 对于给定的分支(如master),GET /repos/:owner/:repo/commits/master确实是最后(最近)的提交.

  • for a given branch (like master), GET /repos/:owner/:repo/commits/master is indeed the last (most recent) commit.

但是您也可以考虑上次推送事件:这表示由用户推送到此存储库的最后一次(最近一次提交)(在任何分支上).

But you can also consider the last push event: that would represent the last and most recent commit done (on any branch), pushed by a user to this repo.

这篇关于我如何从GitHub API获取最后一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆