Long time without writing here
.
So, I need to tell everyone about the GitPython library.
Do you need to interact with Git from Python?. This is your library.
We are gonna create a gitPython object:
>>> from git import *
>>> repo = Repo(“/home/dizquierdo/cvsanaly/”)
Now you have a “Repo” object pointing to your git repository (you need to point to the repository where it can find the .git directory).
If you need to retrieve the commit id:
>>> repo.commits() # by default it takes just up to then commits
or
>>> commits = repo.commits(max_count=100) # it now takes up to 100 commits
Now, imagine you need to guess who was the original committer:
>>> print commits[0].author
>>> print commits[0].id
>>> print commits[0]…
[...]
Finally, do you need to parse the diff between two revisions?
>>> repo.diff(“f930769b432e9608a778aa5c324c8a1567d96510″, “02711dd25e28f81b8d3a00086514a9aa98c78294″)
Most of this information was done using the tutorial written by Michael Trier
Cheers!
Posted by dicortazar