git log --follow, the gitpython way
Asked Answered
C

2

43

I am trying to access the commit history of a single file as in:

git log --follow -- <filename>

I have to use gitpython, so what I am doing now is:

import git 
g = git.Git('repo_dir') 
hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') 

then I build commit objects:

repo = git.Repo('repo_dir')
commits = [repo.rev_parse(c) for c in r]

Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items(), but they both rely on git-rev-list, so they don't have a --follow option.

Colene answered 9/4, 2012 at 12:27 Comment(1)
what is r? repo?Marlborough
S
20

For example,

With range time:

g = git.Git("C:/path/to/your/repo") 
loginfo = g.log('--since=2013-09-01','--author=KIM BASINGER','--pretty=tformat:','--numstat')
print loginfo

Output:

3       2       path/in/your/solutions/some_file.cs

You can see the added lines, removed lines and the file with these changes.

Schmaltz answered 19/11, 2013 at 12:57 Comment(0)
D
5

You can try PyDriller instead (it uses GitPython internally). I'm the owner.

I created it so it's easier to use then other frameworks:

for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
    # here you have the commit object
    print(commit.hash)
Druse answered 8/2, 2019 at 11:7 Comment(1)
You should probably be disclosing that you are the maintainerMidden

© 2022 - 2024 — McMap. All rights reserved.