Quantcast
Channel: Using GitHub API to retrieve all versions of a specific file - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Ivan Zuzak for Using GitHub API to retrieve all versions of a specific file

$
0
0

To get the list of commits relevant for a specific file, use this API endpoint and specify the path parameter:

GET https://api.github.com/repos/:owner/:repo/commits?path=FILE_PATH

You'll get back an array of commit objects, each of which has a sha attribute.

Now that you have all the commit SHAs, you can fetch all the different versions of the file using this API endpoint and by specifying the ref query parameter to set the SHA. So, for each commit SHA, make a request to:

GET https://api.github.com/repos/:owner/:repo/contents/:FILE_PATH?ref=SHA

and read the content attribute. Notice that the content is Base64 encoded, but you can also request a raw version by setting the relevant AcceptHTTP header.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>