Skip to content

Instantly share code, notes, and snippets.

@mikkohei13
Created March 2, 2014 19:59
Show Gist options
  • Save mikkohei13/9312874 to your computer and use it in GitHub Desktop.
Save mikkohei13/9312874 to your computer and use it in GitHub Desktop.
/**
* Gets the last commit date from .git repository
* @param string $gitLocation location of .git/logs/HEAD
* @return string date of last commit YYYY-mm-dd
*/
function gitLastCommitInfo($gitLocation)
{
$commitArray = file($gitLocation); // All commits from file
$lastCommit = array_pop($commitArray); // Latest commit
$lastCommitArray = explode("\t", $lastCommit);
$lastCommitArray2 = explode(" ", $lastCommitArray[0]);
$pop = array_pop($lastCommitArray2); // Remove last array item
return date("Y-m-d", array_pop($lastCommitArray2)); // Format date from second-to-last array item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment