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.
Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.
To view the previous commits, use the git log –-oneline command. This provides the commit details.
To get an overview of recent commits in the whole project, one can look at Overview -> Activity, but commits there are grouped by pushes. Drag your designs here or click to upload.
If you need to get latest commit on a branch through the REST api, try the "/commits" call with the "until" parameter set to the branch you are interested in, and limit=1 to get the single tip commit from the branch. The "authorTimestamp" in the result will tell you when the commit was first created.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With