GitHub API - 如何比较2次提交 [英] GitHub API - how to compare 2 commits

查看:116
本文介绍了GitHub API - 如何比较2次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在两次提交之间获得已更改文件的列表。
类似于
两次提交之间的比较在网络版中,但使用 GitHub Api

解决方案

官方提交比较API是比较两个提交

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




:base :head 可以是分支名称:与:repo 相同的网络中的其他存储库中的repo或分支名称。对于后一种情况,请使用格式 user:branch




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

请注意,您也可以使用标签。

例如:

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,
文件名: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,
补丁:@@ -132,7 +132,7 @@ module test @@ -1000,7 +1000,7 @@ module test
}
]






$ b li>

响应将包含最多250次提交的比较。如果您正在使用更大的提交范围,则可以使用提交列表API 来枚举范围内的所有提交。

  • 为了比较极大的差异,您可能会收到一个错误响应,指出差异耗时过长生成。您可以通过使用较小的提交范围来解决此错误。

  • It's possible to get list of changed files between two commits. Something like that comparison between two commits in web version but using GitHub Api.

    解决方案

    The official commit comparison API is 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
    

    Note that you can use tags as well.
    For instance:

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

    Note the '...', not '..' between the two tags.
    And you need to have the oldest tag first, then the newer tag.

    That gives a status:

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

    And for each commit, information about the files:

    "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"
        }
      ]
    

    BUT:

    • 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.

    这篇关于GitHub API - 如何比较2次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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