Last active
October 2, 2019 08:05
-
-
Save forsvunnet/27b3b195f182f3e51387a2ac4d1cb06c to your computer and use it in GitHub Desktop.
Delete files that are from a specific commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rglob($pattern, $flags = 0) { | |
// https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file | |
$files = glob($pattern, $flags); | |
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { | |
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags)); | |
} | |
return $files; | |
} | |
$files = rglob('*'); | |
foreach ($files as $file) { | |
if ($file) | |
check( $file ); | |
} | |
function check( $file ) { | |
if ( is_dir( $file ) ) { | |
return; | |
} | |
$delete = ['1c97839', '0575f45']; | |
$result = trim(`git log -n1 --pretty="%h;%cn;%s" -- $file`); | |
if ( ! $result ) { | |
echo "\e[0;31m$file\e[0m\n"; | |
return; | |
} | |
$cols = explode( ';', $result ); | |
if ( 3 !== count( $cols ) ) { | |
var_dump($result); | |
die( "Something went wrong!\n" ); | |
} | |
list($hash, $name, $subject) = $cols; | |
if ( in_array( $hash, $delete ) ) { | |
echo "\e[9;1;31m$file\e[0m\n"; | |
unlink($file); | |
return; | |
} | |
echo str_pad( "\e[1;37m$file\e[0m", 80 ); | |
echo " \e[0;35m$hash\e[0m "; | |
echo str_pad( "\e[0;34m$name\e[0m", 30 ); | |
if (strlen($subject) > 80) { | |
echo "\n\e[1;37m└─\e[0m $subject\n"; | |
} else { | |
echo " $subject\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment