Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

git - How can I get last commit from GitHub API

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

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It depends on your definition of "last".

  • 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...