8

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.

Rana
  • 5,912
  • 12
  • 58
  • 91

2 Answers2

9

A follow-on, to read each file:

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:
    ...
Eric
  • 95,302
  • 53
  • 242
  • 374
6

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.

Byron
  • 3,908
  • 3
  • 26
  • 35