Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用GitPython反向读取提交_Python_Gitpython - Fatal编程技术网

使用GitPython反向读取提交

使用GitPython反向读取提交,python,gitpython,Python,Gitpython,是否有一种方法可以使用GitPython库反向迭代提交,即从最旧的提交到最新的提交,方式与以下类似: >>> from git import Repo >>> repo = Repo('/path/to/repo') >>> for commit in reversed(repo.iter_commits()): ... print commit ... Traceback (most recent call last): Fi

是否有一种方法可以使用GitPython库反向迭代提交,即从最旧的提交到最新的提交,方式与以下类似:

>>> from git import Repo
>>> repo = Repo('/path/to/repo')
>>> for commit in reversed(repo.iter_commits()):
...     print commit
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
来自git导入回购的
>
>>>repo=repo('/path/to/repo')
>>>对于反向提交(repo.iter_commits()):
...     打印提交
... 
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:reversed()的参数必须是序列

不必首先将所有内容都包含在内存中,因为我的情况是处理大量提交(例如linux内核)

查看,似乎
iter\u提交
正在将其kwargs传递给
git rev list
。查看its发现它接受了一个
--reverse
标志,因此人们只能猜测
repo.iter\u提交(reverse=True)
会起作用。

这里的主要问题是,在reverse中,您需要传递序列。但是iter_提交返回一个迭代器。 所以你可以
commitList=list(repo.iter\u commits())


然后使用commitList上的reverselogic

OP stated
,而不必首先包含内存中的所有内容
。你就是这么做的哦,对不起。