Skip to content

Instantly share code, notes, and snippets.

@philipmat
Created August 14, 2014 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipmat/8a292387dcef0bad9404 to your computer and use it in GitHub Desktop.
Save philipmat/8a292387dcef0bad9404 to your computer and use it in GitHub Desktop.
Output the content of all git objects changed between two dates (useful for when the repo gets borked)
# Usage: (execute in the .git/objects folder)
# recover.ps1 -startDate "8/13/2014 1:22:00pm" -endDate "8/13/2014 8:00:00pm" > borked_files.txt
[CmdletBinding()]
Param(
[string]$startDate,
[string]$endDate
)
$start = [datetime]::Today
if ($startDate) {
$start = [datetime]::Parse($startDate)
}
$end = $start.AddDays(1)
if ($endDate) {
$end = [datetime]::Parse($endDate)
}
Write-Host "Searching for git objects created between $start and $end"
$files = Get-ChildItem -recurse | where {$_.CreationTime -gt $start -and $_.CreationTime -lt $end}
$sha_length = "fe19a805b91c63cca33f53c56499fa53b2436303".Length
$count_files = $files.Length
Write-Host "Files: $count_files"
$i = 0
foreach ($file in $files) {
$composed = $file.Directory.BaseName + $file.BaseName
if ($composed.Length -eq $sha_length) {
Write-Output "----=====SHA1: $composed"
git show $composed
$i++
Write-Host -NoNewline "."
if ($i % 50 -eq 0) { Write-Host -ForegroundColor Green "= $i/$count_files" }
} else {
Write-Host -ForegroundColor DarkRed "Ignoring: $composed"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment