Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 776
Rana Avatar asked Mar 02 '15 06:03

Rana


2 Answers

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:
    ...
like image 94
Eric Avatar answered Oct 19 '22 13:10

Eric


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.

like image 5
Byron Avatar answered Oct 19 '22 11:10

Byron