【问题标题】:GitHub Api: How to get Root :tree_sha of a repository?GitHub Api:如何获取存储库的 Root :tree_sha?
【发布时间】:2010-05-14 00:29:43
【问题描述】:

如何通过 GitHub API 获取 GitHub 存储库的 Root :tree_sha?

GitHib API 帮助页面似乎没有解释这一关键信息:

http://develop.github.com/p/object.html

可以一棵一棵树的获取内容 SHA

tree/show/:user/:repo/:tree_sha

获取根树的列表 我们提交的 facebox 项目 列表,我们可以这样称呼:

$ 卷曲 http://github.com/api/v2/yaml/tree/show/defunkt/facebox/a47803c9ba26213ff194f042ab686a7749b17476

【问题讨论】:

    标签: github github-api


    【解决方案1】:

    每个提交都包含该提交时整个树的 sha。 使用 API 获取表示 master 分支的 JSON 对象。

    https://api.github.com/repos/:owner/:repo/branches/master
    

    该分支的最后一次提交包括我认为您要求的树的 sha。

    这段代码演示了如何在 Python 中获取head_tree_sha

    import requests
    token = '0...f'
    key = {'Authorization':'token '+token}
    master = requests.get('https://api.github.com/repos/'+owner+'/' + repo '/branches/master', headers=key)
    master = master.json()
    head_tree_sha = master['commit']['commit']['tree']['sha']
    

    https://developer.github.com/v3/git/commits/

    【讨论】:

      【解决方案2】:

      http://develop.github.com/p/commits.html

      提交告诉你它的树形。

      [编辑]
      如果您想将子文件夹 cd 的树 sha 放入您感兴趣的文件夹的父文件夹并运行:
      git ls-tree HEAD

      如果你想要根树 sha:
      git show HEAD --format=raw
      第一行有提交 sha
      第二行有树形

      【讨论】:

        【解决方案3】:

        我不确定 GitHub API — 但是,如果您只需要哈希值,您可以在克隆中使用此命令:

        git show HEAD --format=%T | head -1
        

        或者使用%t作为缩写哈希。

        【讨论】:

        • 这很好用,但我不敢投票,因为这个问题是 GitHub 特有的。
        猜你喜欢
        • 2021-02-26
        • 2017-09-01
        • 2019-09-30
        • 2014-09-29
        • 2013-12-11
        • 1970-01-01
        • 1970-01-01
        • 2022-11-03
        • 1970-01-01
        相关资源
        最近更新 更多