首页 > 解决方案 > 在 GitPython 中迭代提交 b/w 2 个指定的提交

问题描述

import git
repo = git.Repo(repo_dir)
ref_name = 'master'
for commit in repo.iter_commits(rev=ref_name):
     <some code here>

此代码遍历所有提交。我想迭代 b/w 2 提交。就像git log commit1...commit2

如何使用 GitPython 的 iter_commits() 方法来做同样的事情。

标签: pythongitloopscommitgitpython

解决方案


repo.iter_commits(rev='1234abc..5678def')为我工作GitPython==2.1.11

例子:

repo = git.Repo(repo_dir)
for commit in repo.iter_commits(rev='master..HEAD'):
     <some code here>

推荐阅读