在python中,我希望获取git存储库中文件的所有提交日志,并解析日志中的信息(散列、作者姓名、作者邮件、作者日期、提交者姓名、提交者邮件、提交日期和提交消息)。目前,我可以使用gitpython或通过子进程调用shell命令来获取原始git日志。在
使用gitpython:
g=git.Git(path)
loginfo=g.log("--pretty=fuller",'--follow',"<filename>")
使用子程序调用:
^{pr2}$但是,在这之后,我想解析原始日志,但是在gitpython中找不到合适的库/方法。另外,我还希望日期以python日期时间格式进行解析。你能帮忙吗?在
您可以考虑使用PyDriller,这是一个围绕GitPython的包装器,它使这些事情变得更简单。有一个名为
get_commits_modified_file()
的函数:然后您可以:
^{pr2}$您可以使用以下方法获取所有存储库提交:
然后您就可以确定gitpython提供了什么样的数据:
^{pr2}$其中包括:
举个例子:
如果要检查提交是否包含文件(如果 你想从该文件获取所有提交)。您可以使用:
然后从文件中获取所有提交:
例如,我想从'初始标高'文件:
确保功能正常工作:
希望有帮助。在
相关问题 更多 >
编程相关推荐