如何使用GitPython计算未发布的提交?

Gr1*_*r1N 3 python git gitpython

随着git status我可以了解未公布的提交计数信息:

» git status             
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

我想用GitPython获取未发布的提交(或计数).我找到的文档repo.git.status(),但这不是我想要的.

Chr*_*ial 8

您正在寻找的命令是:

repo.iter_commits('BRANCH..BRANCH@{u}')
Run Code Online (Sandbox Code Playgroud)

或者如果你想要这个作为一个列表:

list(repo.iter_commits('BRANCH..BRANCH@{u}'))
Run Code Online (Sandbox Code Playgroud)

BRANCH@{u}语法是指上游分支BRANCH.

  • 当我知道我有未推送的更改时,这给了我一个空列表。我发现我必须颠倒参数的顺序,才能找到我在本地进行但尚未推送的提交,例如这有效:`list(repo.iter_commits('master@{u}..master'))` (3认同)