Skip to content

Instantly share code, notes, and snippets.

@Icehunter
Created October 18, 2024 01:57
Show Gist options
  • Save Icehunter/b55c27c81721b6745b362840d87f68c8 to your computer and use it in GitHub Desktop.
Save Icehunter/b55c27c81721b6745b362840d87f68c8 to your computer and use it in GitHub Desktop.
function Get-LostBlobs {
# Create the 'lost' directory if it doesn't exist
$lostDir = "lost"
if (-not (Test-Path $lostDir)) {
New-Item -ItemType Directory -Path $lostDir | Out-Null
}
# Run git fsck and filter for lost blobs
git fsck --lost-found | ForEach-Object {
$line = $_
$parts = $line -split ' '
if ($parts[1] -eq 'blob') {
$blob = $parts[2]
# Save the blob content to a file
$blobContent = git cat-file -p $blob
$blobFilePath = Join-Path $lostDir "$blob.txt"
Set-Content -Path $blobFilePath -Value $blobContent
}
}
}
# Execute the function
Get-LostBlobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment