Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用GitPython获取未发布提交的计数?_Python_Git_Gitpython - Fatal编程技术网

如何使用GitPython获取未发布提交的计数?

如何使用GitPython获取未发布提交的计数?,python,git,gitpython,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 我想用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

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

您要查找的命令是:

repo.iter_commits('BRANCH..BRANCH@{u}')
或者,如果您希望将其作为列表:

list(repo.iter_commits('BRANCH..BRANCH@{u}'))

BRANCH@{u}
语法指的是
BRANCH

的上游分支,感谢@Chronial和@Clare Macrae的反馈 使用
==3.1.11
,我是这样做的:

branch=self.repo.active\u分支
无刷⇡' if list(self.repo.iter_提交(f'{branch}@{{u}}..{branch}'))else常量.NOTHING
未拔出的\u符号⇣' if list(self.repo.iter_提交(f'{branch}..{branch}@{u}'))else常量.NOTHING

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