When I run git log, I get the this line for each commit: "Author: name < email >". How do I get the exact same format for a commit in Python for a local repo? When I run the code below, I get just the author name.
from git import Repo
repo_path = 'mockito'
repo = Repo(repo_path)
commits_list = list(repo.iter_commits())
for i in range(5):
commit = commits_list[i]
print(commit.hexsha)
print(commit.author)
print(commit.committer)
According to the gitpython API documentation, a commit object—an instance of class git.objects.commit.Commit—has author and committer attributes that are instances of class git.util.Actor, which in turn has fields conf_email, conf_name, email, and name.
Hence (untested):
print(commit.author.name, commit.author.email)
will likely get you the two fields you want, though you may wish to format them in some way.
Edit: I'll defer to Gino Mempin's answer since I don't have gitpython installed to test this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With