Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get last commit from GitHub API

Tags:

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.

like image 591
Rogelio Blanco Avatar asked Aug 17 '17 03:08

Rogelio Blanco


People also ask

How can I see last commit in GitHub?

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.

How do I get the last commit code?

To view the previous commits, use the git log –-oneline command. This provides the commit details.

How do you find last commit on Gitlab?

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.

How do you check the last commit on a branch?

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.


1 Answers

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.

like image 129
VonC Avatar answered Oct 10 '22 04:10

VonC