-
-
Save miquelbotanch/0f2b5786b36707db571b to your computer and use it in GitHub Desktop.
Parse git log with PHP to an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Orginal Author: Ngo Minh Nam | |
$dir = "/path/to/your/repo/"; | |
chdir($dir); | |
$output = array(); | |
exec('git log -200 --pretty=format:%at%n%an%n%ae%n%h%n%s',$output); | |
$history = array(); | |
$field = 0; | |
foreach ($output as $line) { | |
if ($field == 0) { $commit["date"] = $line; }else // unixtimestamp format | |
if ($field == 1) { $commit["author"] = $line; }else | |
if ($field == 2) { $commit["email"] = $line; }else | |
if ($field == 3) { $commit["version"] = $line; }else | |
if ($field == 4) { $commit["subject"] = $line; | |
$history[] = $commit; | |
unset($commit); | |
$field=-1; | |
} | |
$field++; | |
} | |
print "<pre>".print_r($history,true)."</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment