使用 GitPython 反向读取提交

nul*_*ull 2 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):
  File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
Run Code Online (Sandbox Code Playgroud)

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

Dee*_*ace 6

查看文档,似乎正在iter_commits将其 kwargs 传递给git-rev-list. 查看其文档表明它接受一个--reverse标志,因此只能猜测这repo.iter_commits(reverse=True)会起作用。