7

我正在使用gitpython库来执行 git 操作,从 python 代码中检索 git 信息。我想检索特定文件的所有修订。但在docs上找不到具体的参考资料。

任何人都可以提供一些关于哪个功能在这方面有帮助的线索吗?谢谢。

4

2 回答 2

6

后续,读取每个文件:

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:
    ...
于 2015-10-27T17:28:53.777 回答
5

没有这样的功能,但很容易实现:

import git
repo = git.Repo()
path = "dir/file_you_are_looking_for"

commits_touching_path = list(repo.iter_commits(paths=path))

即使涉及多条路径,性能也会适中。可以在 github 上的问题中找到基准和更多代码。

于 2015-03-02T08:45:35.257 回答