Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitPython get commit for a file

Tags:

git

python

I'm looking to use gitpython to get data on a tree.. to list when the file was commit and the log given.. as far as I have gotten is

from git import *
repo = get_repo("/path/to/git/repo")
for item in repo.tree().items():
    print item[1]

That just lists things like

<git.Tree "ac1dcd90a3e9e0c0359626f222b99c1df1f11175">
<git.Blob "764192de68e293d2372b2b9cd0c6ef868c682116">
<git.Blob "39fb4ae33f07dee15008341e10d3c37760b48d63">
<git.Tree "c32394851edcff4bf7a452f12cfe010e0ed43739">
<git.Blob "6a8e9935334278e4f38f9ec70f982cdc4f42abf0">

I don't see anywhere in the git.Blog docs that you can get this data.. am I barking up the wrong tree?

like image 874
Mike Avatar asked Feb 27 '23 10:02

Mike


2 Answers

Anyone looking to do this now it would be:

Last 100 sorted in descending order:

repo.iter_commits('master', max_count=100)

You can use skip for paging:

repo.iter_commits('master', max_count=10, skip=20)

Reference: http://gitpython.readthedocs.org/en/stable/tutorial.html#the-commit-object

like image 111
Coder1 Avatar answered Mar 05 '23 18:03

Coder1


After 4 hours.. I finally got it

repo = get_repo("/path/to/git/repo")

items = repo.tree().items()
items.sort()

for i in items:
    c = repo.commits(path=i[0], max_count=1)
    print i[0], c[0].author, c[0].authored_date, c[0].message
like image 40
Mike Avatar answered Mar 05 '23 19:03

Mike