当我运行git log
时,每次提交都会得到以下行:“作者:姓名”。如何为本地存储库的Python提交提供完全相同的格式?当我运行下面的代码时,我只会得到作者的名字。
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)
根据the gitpython API documentation,commit object-class git.objects.commit.Commit
的实例-具有author
和committer
属性,它们是class git.util.Actor
的实例,而这些属性又具有字段class git.util.Actor
,conf_email
, conf_name
和email
。
因此(未试用):
name
尽管您可能希望以某种方式设置它们的格式,但可能会为您提供两个所需的字段。
Edit:因为我没有安装gitpython来进行测试,所以我将遵循print(commit.author.name, commit.author.email)
。
似乎gitpython的Gino Mempin's answer对象没有作者电子邮件的属性。
您还可以将gitpython用于Commit
。您可以使用call git commands directly命令,传入commit HASH(来自git show
),然后传入git show
选项,仅提供作者的姓名和电子邮件(当然,您也可以传递所需的其他格式选项)。 >
使用普通git:
commit.hexsha
将gitpython用于
--format
:
--format