You can use pure gitpython for that.
If you want to able to traverse certain commit (assuming the first
commit is HEAD), just use max_count
. See The Commit object
two_commits = list(repo.iter_commits('master', max_count=2))
assert len(two_commits) == 2
if you want similar ability to git log commit1...commit2
as you mentioned:
logs = repo.git.log("--oneline", "f5035ce..f63d26b")
will give you:
>>> logs
'f63d26b Fix urxvt name to match debian repo\n571f449 Add more key for helm-org-rifle\nbea2697 Drop bm package'
You can also use logs = repo.git.log("f5035ce..f63d26b")
but it will give you all info (just like you use git log
without --oneline
)
if you want nice output, use pretty print:
from pprint import pprint as pp
>>> pp(logs)
('f63d26b Fix urxvt name to match debian repo\n'
'571f449 Add more key for helm-org-rifle\n'
'bea2697 Drop bm package')
For more explanation about repo.git.log
, see https://mcmap.net/q/1776120/-how-to-use-git-log-oneline-in-gitpython
git
command on terminal? If yes, you can create a function usingsubprocess
. Then you can call the function to run thegit
command. – BantuCommit.iter_items()
accepts a revision specifier, for which I believe Revision Range is also part of it. Just pass'commit1...commit2'
should do the work. – Postulate