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
  • Select an option

  • Save miquelbotanch/0f2b5786b36707db571b to your computer and use it in GitHub Desktop.

Select an option

Save miquelbotanch/0f2b5786b36707db571b to your computer and use it in GitHub Desktop.

Revisions

  1. miquelbotanch revised this gist Dec 20, 2014. 1 changed file with 15 additions and 24 deletions.
    39 changes: 15 additions & 24 deletions git_history.php
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,21 @@
    <?php
    // Author: Ngo Minh Nam

    // Orginal Author: Ngo Minh Nam
    $dir = "/path/to/your/repo/";
    $output = array();
    chdir($dir);
    exec("git log",$output);
    $output = array();
    exec('git log -200 --pretty=format:%at%n%an%n%ae%n%h%n%s',$output);
    $history = array();
    foreach($output as $line){
    if(strpos($line, 'commit')===0){
    if(!empty($commit)){
    array_push($history, $commit);
    unset($commit);
    $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;
    }
    $commit['hash'] = substr($line, strlen('commit'));
    }
    else if(strpos($line, 'Author')===0){
    $commit['author'] = substr($line, strlen('Author:'));
    }
    else if(strpos($line, 'Date')===0){
    $commit['date'] = substr($line, strlen('Date:'));
    }
    else{
    $commit['message'] .= $line;
    }
    $field++;
    }

    print_r($history);

    ?>
    print "<pre>".print_r($history,true)."</pre>";
  2. @geeknam geeknam revised this gist May 8, 2011. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions git_history.php
    Original file line number Diff line number Diff line change
    @@ -7,22 +7,22 @@
    exec("git log",$output);
    $history = array();
    foreach($output as $line){
    if(strpos($line, 'commit')===0){
    if(!empty($commit)){
    array_push($history, $commit);
    unset($commit);
    }
    $commit['hash'] = substr($line, strlen('commit'));
    }
    else if(strpos($line, 'Author')===0){
    $commit['author'] = substr($line, strlen('Author:'));
    }
    else if(strpos($line, 'Date')===0){
    $commit['date'] = substr($line, strlen('Date:'));
    }
    else{
    $commit['message'] .= $line;
    if(strpos($line, 'commit')===0){
    if(!empty($commit)){
    array_push($history, $commit);
    unset($commit);
    }
    $commit['hash'] = substr($line, strlen('commit'));
    }
    else if(strpos($line, 'Author')===0){
    $commit['author'] = substr($line, strlen('Author:'));
    }
    else if(strpos($line, 'Date')===0){
    $commit['date'] = substr($line, strlen('Date:'));
    }
    else{
    $commit['message'] .= $line;
    }
    }

    print_r($history);
  3. @geeknam geeknam revised this gist May 8, 2011. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_history.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // Author: Ngo Minh Nam

    $dir = "/path/to/your/repo/";
    @@ -24,4 +25,6 @@
    }
    }

    print_r($history);
    print_r($history);

    ?>
  4. @geeknam geeknam revised this gist May 8, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git_history.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // Author: Ngo Minh Nam

    $dir = "/path/to/your/repo/";
    $output = array();
    chdir($dir);
  5. @geeknam geeknam created this gist May 8, 2011.
    25 changes: 25 additions & 0 deletions git_history.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    $dir = "/path/to/your/repo/";
    $output = array();
    chdir($dir);
    exec("git log",$output);
    $history = array();
    foreach($output as $line){
    if(strpos($line, 'commit')===0){
    if(!empty($commit)){
    array_push($history, $commit);
    unset($commit);
    }
    $commit['hash'] = substr($line, strlen('commit'));
    }
    else if(strpos($line, 'Author')===0){
    $commit['author'] = substr($line, strlen('Author:'));
    }
    else if(strpos($line, 'Date')===0){
    $commit['date'] = substr($line, strlen('Date:'));
    }
    else{
    $commit['message'] .= $line;
    }
    }

    print_r($history);