一个后继步骤,用于读取每个文件:
import git
repo = git.Repo()
path = "file_you_are_looking_for"
revlist = (
(commit, (commit.tree / path).data_stream.read())
for commit in repo.iter_commits(paths=path)
)
for commit, filecontents in revlist:
...
虽然没有这样的功能,但很容易实现:
import git
repo = git.Repo()
path = "dir/file_you_are_looking_for"
commits_touching_path = list(repo.iter_commits(paths=path))
即使涉及多条路径,性能也将是适度的。有关此内容的基准测试和更多代码,请参见Github上的问题。