Created
March 4, 2025 18:10
-
-
Save iwatakeshi/1d900dcbfe1fa1717c7e0258e236474e to your computer and use it in GitHub Desktop.
Dangle
This file contains 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
#!/bin/bash | |
# Check if the input file is provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <path-to-temp-file>" | |
exit 1 | |
fi | |
# The input file containing the file content (e.g., the temp-file extracted from git show) | |
temp_file="$1" | |
# Hash the file content using sha256sum | |
file_hash=$(sha256sum "$temp_file" | cut -d ' ' -f 1) | |
echo "File hash: $file_hash" | |
# Iterate through dangling blobs and compare with file hash | |
echo "Searching for matching dangling blobs..." | |
git fsck --full | grep dangling | cut -d ' ' -f 3 | while read blob; do | |
# Compare each dangling blob with the file hash | |
if git cat-file blob "$blob" | sha256sum | cut -d ' ' -f 1 | grep -q "$file_hash"; then | |
echo "Found matching blob: $blob" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment