2

Is there a way to iterate commits in reverse using the GitPython lib, that is, from the oldest one to the newest, in a similar manner to:

>>> 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

Without having to include everything in memory first, as my case is dealing with lots of commits (e.g. the linux kernel)?

2 Answers 2

8

Looking at the documentation it appears that iter_commits is passing its kwargs to git-rev-list. Looking at its documentation reveals that it accepts a --reverse flag, so one can only guess that repo.iter_commits(reverse=True) would work.

Sign up to request clarification or add additional context in comments.

Comments

-1

The main problem here is that in reverse you need to pass the sequence. but iter_commits return an iterator. so you can do commitList = list(repo.iter_commits())

and then use the reverselogic on the commitList

2 Comments

OP stated Without having to include everything in memory first. You solution does just that
oh I am sorry .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.