Get All Revisions for a specific file in gitpython

I am using gitpython library for performing git operations, retrieve git info from python code. I want to retrieve all revisions for a specific file. But couldn't find a specific reference for this on the docs.

Can anybody give some clue on which function will help in this regard? Thanks.


There is no such function, but it is easily implemented:

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

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

Performance will be moderate even if multiple paths are involved. Benchmarks and more code about that can be found in an issue on github.


后续,阅读每个文件:

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:
    ...
链接地址: http://www.djcxy.com/p/22678.html

上一篇: 为什么我不能使用git log

下一篇: 在gitpython中获取特定文件的所有修订