by
3 6
0
3
264k
5
Top 1% !
Pearl of Wisdom
Specified
Popularity: 4838th place

Published on:

No tags for this snippet yet.
LanguagePHP
LicenseMIT_X11
SourceGitHub

Parse git log with PHP to an array

Parse git log with PHP to an array: 
git_history.php
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/252095/Parse-git-log-with-PHP-to-an-array?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?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>";
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus