Python 运行 git 日志命令的方式来获取存储库的详细信息而不克隆它

Python way to run git log command to fetch details of repository without cloning it

是否有 Python 方法 运行 git log 命令来获取存储库的详细信息而不克隆它? 我想在 bitbucket 服务器上 运行 命令来查找存储库的所有活动。

安装 sh 软件包:pip install sh。然后做:

from sh import git

commit_messages = git.log(
    pretty='format:"%h - %an, %ar : %s"', 
    n=50, 
    _tty_out=False
)

或者,仅使用内置模块:

from subprocess import Popen

with Popen(['git', 'log', '--pretty=format:"%h - %an, %ar : %s"']) as proc:
    commit_messages = proc.stdout.read()