Luke Oliff Luke Oliff - 4 months ago 23
PHP Question

i want to display the git version on my site

I want to display the git version number on my site.

I found that it was a commit hash and this wasn't suitable for non-technical users to reference.

I have created this class to display the version 'number' of the current git local to this script.

Answer

Gist: https://gist.github.com/lukeoliff/5501074

<?php

class QuickGit {

  public static function version() {
    exec('git describe --always',$version_mini_hash);
    exec('git rev-list HEAD | wc -l',$version_number);
    exec('git log -1',$line);
    $version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
    return $version;
  }

}
Comments