如何解析git日志中的响应?我需要得到提交散列和提交消息


How to parse the response from git log ? I need to get the commit hash and the commit message

我正在使用shell_exec()函数从php执行命令"git log",并得到以下响应。如何解析响应并获得提交哈希和提交消息?

提交baedf411c58584c4a98f3a632b7f3231500f92c作者:XYZ日期:2016年4月12日星期二23:04:33+0530提交第三次提交提交251654c5f6f256fe6e23c2c85f1a70594aae0d4作者:XYZ日期:2016年4月12日星期二22:37:21+0530提交第二次提交提交3be3198a20d902e24e6b187cd0666ed0d5e6c4d作者:XYZ日期:2016年4月12日星期二22:34:31+0530初始提交

您可以执行下一步操作:

git log --oneline --format="%H %s"

如果需要在php中使用此输出,可以在值之间添加一些键,并在每行中使用explode()来获取值。例如:

git log --oneline --format=%H:::%s

其中:::是去分隔符,在php中使用它会爆炸。

我希望这有帮助:D

使用git log --oneline而不是git log