Php 如何解析来自git日志的响应?我需要获取提交散列和提交消息
我使用shell_exec()函数从php执行命令“git log”,并得到以下响应。如何解析响应并获取提交哈希和提交消息 commit baedfa411c58584c4a98f3a632b7f3231500f92c Author: XYZ Date: Tue Apr 12 23:04:33 2016 +0530 commiting 3rd commit commit 251654c5f6f256fe6e23c2c85f1a70594aae00d4 Author: XYZ Date: Tue Apr 12 22:37:21 2016 +0530 commiting 2nd commit commit 3be3198a20d902e24e6b187cd0666ed0d5ee6c4d Author: XYZ Date: Tue Apr 12 22:34:31 2016 +0530 initial commit 提交BAEDFA411C584C4A98F3A632B7F3231500F92C 作者:XYZ 日期:2016年4月12日星期二23:04:33+0530 提交第三次提交 提交251654c5f6f256fe6e23c2c85f1a70594aae00d4 作者:XYZ 日期:2016年4月12日星期二22:37:21+0530 提交第二次提交 提交3be3198a20d902e24e6b187cd0666ed0d5ee6c4d 作者:XYZ 日期:2016年4月12日星期二22:34:31+0530 初始提交 使用Php 如何解析来自git日志的响应?我需要获取提交散列和提交消息,php,git,parsing,preg-match-all,Php,Git,Parsing,Preg Match All,我使用shell_exec()函数从php执行命令“git log”,并得到以下响应。如何解析响应并获取提交哈希和提交消息 commit baedfa411c58584c4a98f3a632b7f3231500f92c Author: XYZ Date: Tue Apr 12 23:04:33 2016 +0530 commiting 3rd commit commit 251654c5f6f256fe6e23c2c85f1a70594aae00d4 Author: XYZ Date:
git log--oneline
而不是git log
使用git log--oneline
而不是git log
您可以执行以下操作:
git log --oneline --format="%H %s"
如果需要在php中使用此输出,可以在值之间添加一些键,并在每行中使用explode()
来获取值。例如:
git log --oneline --format=%H:::%s
其中,:
是反分隔符,在php中使用它将被分解
我希望这有帮助:D你可以做下一步:
git log --oneline --format="%H %s"
如果需要在php中使用此输出,可以在值之间添加一些键,并在每行中使用explode()
来获取值。例如:
git log --oneline --format=%H:::%s
其中,:
是反分隔符,在php中使用它将被分解
我希望这有帮助:D不要解析来自
git log
输出的任何内容,因为它可能会在未来的git版本中更改。改用较低级别的Git命令,如Git rev list
。不要解析Git log
输出中的任何内容,因为它可能会在未来的Git版本中更改。而是依赖较低级别的Git命令,例如Git rev list
。