Created
August 2, 2023 02:10
-
-
Save linux4life798/48469d09016890928aff998256901036 to your computer and use it in GitHub Desktop.
Find a text change that might have been seen by Git's dangling blob/commit history
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 | |
# Craig Hesling | |
# | |
# Find a change in Git's vast dangling blob/commmit archive. | |
# | |
# Usage: find-change.bash <grep-pattern1> [<grep-patter2> [grep-patterns...]] | |
mapfile -t LOST < <(git fsck --lost-found) | |
PATTERNS=( "$@" ) | |
for item in "${LOST[@]}"; do | |
echo "# Checking out git '${item}'." | |
git_type=$(cut -d' ' -f2 <<<"${item}") | |
git_hash=$(cut -d' ' -f3 <<<"${item}") | |
case $git_type in | |
commit) | |
for pattern in "${PATTERNS[@]}"; do | |
git show $git_hash | grep "${pattern}" | |
done | |
;; | |
blob) | |
for pattern in "${PATTERNS[@]}"; do | |
git cat-file blob $git_hash | grep "${pattern}" | |
done | |
;; | |
tree) | |
# Could search git trees. | |
echo "Don't know how to look at this" | |
;; | |
*) | |
echo "Unknown type" | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment