Skip to content

Instantly share code, notes, and snippets.

@dwolke
Forked from stevegrunwell/get_current_git_commit.php
Last active August 29, 2015 14:15
Show Gist options
  • Save dwolke/4101c28cebc30c314d7f to your computer and use it in GitHub Desktop.
Save dwolke/4101c28cebc30c314d7f to your computer and use it in GitHub Desktop.
<?php
/**
* Get the hash of the current git HEAD
* @param str $branch The git branch to check
* @return mixed Either the hash or a boolean false
*/
function get_current_git_commit( $branch='master' ) {
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
return $hash;
} else {
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment