Skip to content

Instantly share code, notes, and snippets.

@miquelbotanch
Forked from geeknam/git_history.php
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miquelbotanch/0f2b5786b36707db571b to your computer and use it in GitHub Desktop.
Save miquelbotanch/0f2b5786b36707db571b to your computer and use it in GitHub Desktop.
Parse git log with PHP to an array
<?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