【问题标题】:How to get count of unpublished commit with GitPython?如何使用 GitPython 获取未发布提交的计数?
【发布时间】:2013-04-06 10:16:13
【问题描述】:

使用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(),但这不是我想要的。

【问题讨论】:

    标签: python git gitpython


    【解决方案1】:

    您要查找的命令是:

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

    或者如果你想把它作为一个列表:

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

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

    【讨论】:

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

    感谢@Chronial 和@Clare-Macrae 的反馈 使用gitPython==3.1.11,我是这样做的:

    branch = self.repo.active_branch
    unpushed_symbol = '⇡' if list(self.repo.iter_commits(f'{branch}@{{u}}..{branch}')) else constants.NOTHING
    unpulled_symbol = '⇣' if list(self.repo.iter_commits(f'{branch}..{branch}@{{u}}')) else constants.NOTHING
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 2015-11-04
      • 2012-12-29
      • 2016-07-25
      • 1970-01-01
      相关资源
      最近更新 更多