开发者

GitPython get commit for a file

开发者 https://www.devze.com 2023-01-12 02:52 出处:网络
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

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 "c32394851edcff4bf7a452f12cfe010e开发者_如何学C0ed43739">
<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?


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


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


The commit message is in the commit object, not tree object. I guess you can get it with

repo.heads[0].commit.message

(note: I don't know python. this is based on my git knowledge and a minute on reading the api docs)


I believe you can use blob.data_stream() to get a file-like object containing the raw contents of the data.

I've never used this API before, though, so I could be off a bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消