【问题标题】:Get commits from a specific branch in github从 github 中的特定分支获取提交
【发布时间】:2019-07-30 15:24:10
【问题描述】:

想要从不同的分支而不是主分支获取提交。它列出了来自 master 分支的提交。我的 Repo master 和测试中有 2 个分支,我想要来自测试分支而不是 master 的提交。

我已经尝试过以下方法从 github repo 获取列表,但它提供了 master 分支的提交

github_commits = repo.get_commits()

我尝试过的完整代码:

from github import Github  

g = Github(base_url="https://my_hostnaame/api/v3", 
login_or_token="my_access_token") 
org = g.get_organization("my_org") 
repo = org.get_repo("my_repo_name") 
github_commits = repo.get_commits()
print(github_commits)

【问题讨论】:

    标签: python github


    【解决方案1】:

    您需要执行以下操作:

    branch = g.get_repo("my_repo_name").get_branch("master")
    print(branch.commit)
    

    我假设你安装了PyGithub

    here is the full usage of branch method

    【讨论】:

    • 我已经安装了 PyGithub
    • 我们也可以用于组织吗?
    • 我正在使用 Github Enterprise 并想为组织下的 repos 做些什么
    猜你喜欢
    • 1970-01-01
    • 2011-09-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    相关资源
    最近更新 更多