Git Python 好像不行

Git Python seems not work

我从 python 开始并尝试使用 GitPython,我拼命地尝试使这个模块工作。

我在许多网站上看到文档很差,我遵循的示例似乎不起作用。

我已经在 Windows (2012/ Python 3.5) 上试过了:

# -*-coding:Latin-1 -*

from git import *

path = ('C:\Users\me\Documents\Repos\integration')
repo = Repo(path)
assert repo.bare == False

repo.commits()

os.system("pause")

这是 Linux (Debian/Python 2.7) :

from git import Repo

repo = Repo('/home/git/repos/target_repos')
assert repo.bare == False

repo.commits ()

但无论如何,我没有结果......并以这个错误结束:

Traceback (most recent call last):
  File "gitrepo.py", line 6, in <module>
    repo.commits ()
AttributeError: 'Repo' object has no attribute 'commits'

在这两种情况下。

我的问题如下:

  1. 有没有办法让这个模块工作?我找到的所有 link 都是旧的...
  2. 如果是,请帮助我或举个例子。
  3. 如果没有,是否还有其他模块?我正在尝试安装 Dulwich 但没有成功(仅在 Windows 上)
  4. 我见过使用 fab 的方法吗?是否可以用它来操纵 git?

目标是将来管理git与python,以及其他整合的事情。

感谢您的回答。

该模块工作正常,您没有正确使用它。 如果要访问 git 存储库中的提交,请使用 Repo.iter_commits()GitPython.Repo 中不存在您尝试使用的方法 commits()。您可以查看官方模块文档 here 以了解所有支持的操作和属性。

请参阅下面的工作示例

from git import Repo, Commit

path = "test_repository"

repo = Repo(path)

for commit in repo.iter_commits():
    print "Author: ", commit.author
    print "Summary: ", commit.summary

这显示了存储库中每个提交的作者和摘要。 检查 Commit 对象的操作文档并访问它们携带的附加信息(例如提交哈希、日期等)