获取使用GitHub上的blob API文件的所有版本 [英] Getting all versions of a file using GitHub blob api

查看:1496
本文介绍了获取使用GitHub上的blob API文件的所有版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何让所有提交/文件的版本通过GitHub的API(即在提交/版本的内容)。结果
我想这样做的一种方式是等效的答案为<一href=\"http://stackoverflow.com/questions/16700297/using-github-api-to-retrieve-all-versions-of-a-specific-file/16707165#16707165\">this另一个问题。

I want to know how to get all commits/versions of a file (i.e. the contents of the commits/versions) via the GitHub API.
I figured one way to do it which is equivalent to the answer to this other question.

问题是这样使用内容的API,其每个文件1 MB的上限,如果您尝试访问大于1 MB的文件(您收到此错误信息API返回斑点高达1 MB的大小。请求BLOB太大通过API获取,但你可以使用Git的数据API请求斑点高达100 MB的大小。)

The problem is this uses the "contents" API, which has an upper limit of 1 MB per file (you get this error message if you try to access a file larger than 1 MB: "This API returns blobs up to 1 MB in size. The requested blob is too large to fetch via the API, but you can use the Git Data API to request blobs up to 100 MB in size.")

因此​​,要获得的文件比1 MB(100 MB),你需要使用斑点API较大,但我不知道如何在相同的方式,内容的API使用它。

So to get files larger than 1 MB (up to 100 MB) you need to use the "blob" API, but I don't know how to use it in the same way as the contents API.

即,给出了具体提交的文件,你如何得到该文件的使用斑点API的内容?

I.e., given a specific commit of a file, how do you get the contents of that file using the "blob" API?

推荐答案

获取内容的API 确实允许通过一个SHA1:

The get content API indeed allows to pass a SHA1:

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

借助斑点​​API 还采用了SHA1:

GET /repos/:owner/:repo/git/blobs/:sha

但你需要得到你想要第一次将文件的SHA1。

But you need to get the SHA1 of the file you want first.

请参阅我怎么了沙从GitHub API的参数,而无需下载整个文件?,利用获取树API ,在父文件夹。

See "How do I get the "sha" parameter from GitHub API without downloading the whole file?", using the Get Tree API for the parent folder.

GET /repos/<owner>/<repo>/git/trees/url_encode(<branch_name>:<parent_path>)

url_en code(小于branch_name&GT;:&LT; PARENT_PATH&GT;)'是指&LT; branch_name&GT;:&LT; PARENT_PATH&GT ; 必须 URL连接codeD

从树结果会给你你正在寻找的文件的SHA1。

The result from the tree will give you the SHA1 of the file you are looking for.

href=\"http://stackoverflow.com/users/5715113/buddyroo30\"> OP buddyroo30 提到<一的in该评论

The OP buddyroo30 mentions in the comments:

我最后做同样使用树API。结果
  具体来说,我得到一个文件中的所有提交。然后,我尝试使用的内容的API来获取文件内容,每次提交。结果
  如果(所以我需要使用BLOB API即超过1 MB的大小)失败了,我得到了树的URL将文件从它的承诺(即在Perl: $ commit_tree_url = $ commit_info-&GT; {'提交'} - &GT; {'树'} - &GT; {'链接'} )结果。
  然后我取 $ commit_tree_url 并找到在结果的文件正确的树---记录,这将有哪些可以用来获取该文件的URL散列值通过BLOB API内容。

I ended up doing similarly using the tree API.
Specifically, I get all the commits for a file. Then I try to use the contents API to get the file contents for each commit.
If that fails (i.e. over 1 MB in size so I need to use the blob API), I get the tree URL for the file from its commit (i.e. in Perl: $commit_tree_url = $commit_info->{'commit'}->{'tree'}->{'url'}).
then I fetch $commit_tree_url and find the correct tree record in the results for the file --- this will have a 'url' hash value which can be used to get the file contents via the blob API.

这篇关于获取使用GitHub上的blob API文件的所有版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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