33 lines
912 B
Bash
33 lines
912 B
Bash
#!/bin/bash
|
|
|
|
# Location of the Git objects directory.
|
|
# Change this if your setup is different.
|
|
OBJECTS_DIR="./objects"
|
|
|
|
# Loop over the 256 possible first two characters of the SHA-1 hash.
|
|
for dir in $(ls -1 $OBJECTS_DIR); do
|
|
# Ignore the 'info' and 'pack' special directories.
|
|
if [ "$dir" == "info" ] || [ "$dir" == "pack" ]; then
|
|
continue
|
|
fi
|
|
|
|
# Loop over the object files in each directory.
|
|
for file in $(ls -1 $OBJECTS_DIR/$dir); do
|
|
# Concatenate the directory and file names to get the full SHA-1 hash.
|
|
full_hash="${dir}${file}"
|
|
|
|
# Use git cat-file to find the type of the object.
|
|
obj_type=$(git cat-file -t $full_hash 2> /dev/null)
|
|
|
|
# If git cat-file fails, skip this object.
|
|
if [ $? -ne 0 ]; then
|
|
continue
|
|
fi
|
|
|
|
# If the object is a commit, print its hash.
|
|
if [ "$obj_type" == "commit" ]; then
|
|
echo "Found commit: $full_hash"
|
|
fi
|
|
done
|
|
done
|