Попробуйте код:
import git
repo_path = 'foo'
repo = git.Repo(repo_path)
# get all commits reachable from "HEAD"
commits = list(repo.iter_commits('HEAD'))
# get the number of commits
count = len(commits)
Я не знаком с Python 3.x. Могут быть ошибки из-за различий между Python 2.x и 3.x.
Проведя некоторое исследование, я обнаружил, что мы можем просто вызвать git rev-list --count HEAD
прямым способом.
import git
repo_path = 'foo'
repo = git.Repo(repo_path)
count = repo.git.rev_list('--count', 'HEAD')
Обратите внимание, что -
в имени команды должно быть _
в коде.