I want to format git-log match in a convenient way.
The output of git-log command is given:
commit 11ae9c97409fb349e2bfa50ed65bd23ec6dbca70
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:51:30 2012 +0200
updated VERSION for 2.0.16
commit 6e14d67cb23439d6700f494e29e809811edeeade
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:50:55 2012 +0200
update CONTRIBUTORS for 2.0.16
commit 0341492ed566fca8df556573b9664f691c5dff3d
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:48:12 2012 +0200
updated CHANGELOG for 2.0.16
commit b18f6f557b5db1e2e6d2c2c0494e0564b91f438d
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Tue Jul 10 15:28:02 2012 +0200
[Console] fixed wrong phpdoc (closes #4394)
I want to format as given below:
Fabien Potencier, Wed Jul 11 19:51:30 2012 +0200
updated VERSION for 2.0.16
Fabien Potencier, Wed Jul 11 19:50:55 2012 +0200
update CONTRIBUTORS for 2.0.16
Fabien Potencier, Wed Jul 11 19:48:12 2012 +0200
updated CHANGELOG for 2.0.16
Fabien Potencier, Tue Jul 10 15:28:02 2012 +0200
[Console] fixed wrong phpdoc (closes #4394)
for that I wrote a PHP script as given below.
<?php
$r = shell_exec('git log');
$p = '/commit (.{2})(.{4})(.{6})/';// THIS SHOULD CHANGE!
preg_match_all($p, $r, $match);
unset($match[0]);
$output = array();
foreach($match as $k1=> $v1)
foreach($v1 as $k2=>$v2)
@$output[$k2] .= $v2 . ($k1==1 ? ',' : PHP_EOL);
echo implode('', $output);
I don’t have any idea about the pattern I should be used here. Please help me.
Something along these lines should do the trick:
Three backreferences set, one for each set of data you want.
Print the
$match-array if you need help understanding the saved data.Demo+explanation: http://regex101.com/r/cA0lD3