gpt4 book ai didi

GitHub API - 如何比较 2 个提交

转载 作者:行者123 更新时间:2023-12-03 01:16:06 25 4
gpt4 key购买 nike

可以获取两次提交之间更改的文件列表。类似的东西 comparison between two commits在网络版本中但使用 GitHub Api .

最佳答案

官方提交比较 API 是 Compare two commits :

GET /repos/:owner/:repo/compare/:base...:head

Both :base and :head can be either branch names in :repo or branch names in other repositories in the same network as :repo. For the latter case, use the format user:branch:

GET /repos/:owner/:repo/compare/user1:branchname...user2:branchname

请注意,您也可以使用标签或提交 SHA。例如:

https://api.github.com/repos/git/git/compare/v2.2.0-rc1...v2.2.0-rc2

请注意两个标记之间的“...”,而不是“..”。
并且您需要首先拥有最旧的标签,然后是较新的标签。

这给出了一个状态:

  "status": "behind",
"ahead_by": 1,
"behind_by": 2,
"total_commits": 1,

对于每个提交,有关文件的信息:

"files": [
{
"sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
"filename": "file1.txt",
"status": "added",
"additions": 103,
"deletions": 21,
"changes": 124,
"blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
"patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
}
]

但是:

  • The response will include a comparison of up to 250 commits. If you are working with a larger commit range, you can use the Commit List API to enumerate all commits in the range.

  • For comparisons with extremely large diffs, you may receive an error response indicating that the diff took too long to generate. You can typically resolve this error by using a smaller commit range.

<小时/>

注释:

同一网络”表示:由同一 Git 存储库托管服务托管的两个存储库(例如 github.com 上的两个存储库,或同一本地 GHE 上的两个存储库 -- GitHub Enterprise --实例)

因此,您可以比较存储库及其分支之间的两个分支。
示例:

https://api.github.com/repos/030/learn-go-with-tests/compare/master...quii:master

(此示例将 fork 与其原始存储库进行比较,而不是将原始存储库与 fork 进行比较:这是因为在本例中, fork 位于原始存储库之后)

<小时/>

正如 Tom Carver 所指出的在 the comments :

this suggested API silently maxes out at 300 files shown;
I haven't yet found an API that avoids this limitation

关于GitHub API - 如何比较 2 个提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26925312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com