Basically the command within PHP
exec('git log', $result);
print_r($result);
result:
Array
(
[0] => commit 693673def6d3cb8f196cf5988af70b87c4ff4cb3
[1] => Author: None <[email protected]>
[2] => Date: Wed Nov 7 23:14:14 2018 -0200
[3] =>
[4] => Create README.md
[5] =>
[6] => commit f0a3ce8f990a693352b597e51ac2a874e07da2fa
[7] => Author: None <[email protected]>
[8] => Date: Wed Nov 7 23:02:55 2018 -0200
[9] =>
[10] => Create index.php
)
Now is to work the information your way by building a new array
, example:
<?php
exec('git log', $result);
$new_result = array();
$j = -1;
for($i = 0; $i < count($result); $i++)
{
if (strpos($result[$i],'commit') !== false)
{
$new_result[++$j]['commit'] = substr($result[$i], strlen('commit'));
}
else if (strpos($result[$i],'Author:') !== false)
{
$new_result[$j]['author'] = substr($result[$i], strlen('Author:'));
}
else if (strpos($result[$i],'Date:') !== false)
{
$new_result[$j]['date'] = substr($result[$i], strlen('Date:'));
}
else if (!empty($result[$i]))
{
$new_result[$j]['message'] = trim($result[$i]);
}
}
print_r($new_result);
result:
Array
(
[0] => Array
(
[commit] => 693673def6d3cb8f196cf5988af70b87c4ff4cb3
[author] => None <[email protected]>
[date] => Wed Nov 7 23:14:14 2018 -0200
[message] => Create README.md
)
[1] => Array
(
[commit] => f0a3ce8f990a693352b597e51ac2a874e07da2fa
[author] => None <[email protected]>
[date] => Wed Nov 7 23:02:55 2018 -0200
[message] => Create index.php
)
)