Skip to content

Instantly share code, notes, and snippets.

@yesmeck
Created November 25, 2011 09:05
Show Gist options
  • Save yesmeck/1393094 to your computer and use it in GitHub Desktop.
Save yesmeck/1393094 to your computer and use it in GitHub Desktop.
Git lost found.
#!/usr/bin/php
<?php
if (!isset($_SERVER['argv'][1])) {
exit('参数错误');
}
$search = $_SERVER['argv'][1];
$output = shell_exec('git fsck --lost-found | grep commit');
$lines = explode("\n", $output);
foreach($lines as $line) {
$info = explode(' ', $line);
if(isset($info[2])) {
$hash = $info[2];
$output = shell_exec('git show ' . $hash);
if(strpos($output, $search) !== FALSE) {
echo $line . "\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment