Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Created February 9, 2016 05:33
Show Gist options
  • Save ytkhs/8d2f1076baf9f544703b to your computer and use it in GitHub Desktop.
Save ytkhs/8d2f1076baf9f544703b to your computer and use it in GitHub Desktop.
コミットのオブジェクトファイルからコミットハッシュを求めるやり方
<?php
# tmp.txtは `git cat-file -p <commit id>` の中身
$contents = file_get_contents('tmp.txt');
$obj = sprintf("commit %d\0%s", strlen($contents), $contents);
echo sha1($obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment