我正在使用gitpython库来执行git操作,从python代码中检索git信息。我想检索特定文件的所有修订。但是在docs上找不到具体的参考资料。
有人可以提供一些关于哪些功能在这方面有帮助的线索?感谢。
答案 0 :(得分:5)
没有这样的功能,但很容易实现:
import git
repo = git.Repo()
path = "dir/file_you_are_looking_for"
commits_touching_path = list(repo.iter_commits(paths=path))
即使涉及多个路径,性能也会适中。关于can be found in an issue on github的基准和更多代码。
答案 1 :(得分:4)
后续,阅读每个文件:
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:
...