我从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'


在两种情况下。

我的问题如下:


有没有办法使该模块正常工作?我发现的所有链接都是旧的...
如果是,请帮助我或给我一个例子。
如果没有,是否还有其他模块?我正在尝试安装Dulwich,但没有成功(仅在Windows上)
我已经看到有一种使用fab的方法吗?有可能用它来操纵git吗?


目标是将来使用python管理git,以及进行其他集成。

谢谢您的回答。

最佳答案

该模块工作正常,您没有正确使用它。
如果要访问git存储库中的提交,请使用Repo.iter_commits()。您要使用的方法commits()GitPython.Repo中不存在。您可以查看官方模块文档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对象的文档以了解操作并访问其携带的其他信息(例如,提交哈希,日期等)。

10-08 05:18