Created
October 18, 2024 01:57
-
-
Save Icehunter/b55c27c81721b6745b362840d87f68c8 to your computer and use it in GitHub Desktop.
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
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