In Git, how do I find the SHA-1 IDs of all blobs in the object database that contain a string pattern? git-grep
provides only the file paths and not the sha1 IDs.
EDIT: Update based on new testing results using Git version 2.7.4
Looks like the solution I posted only goes through the reflog. So if you delete a reflog entry, that entry will not be searched through - even though the object still exists.
So you will have to do something like:
{
git rev-list --objects --all --grep="text"
git rev-list --objects -g --no-walk --all --grep="text"
git rev-list --objects --no-walk --grep="text" \
$(git fsck --unreachable |
grep '^unreachable commit' |
cut -d' ' -f3)
} | sort | uniq
Derived from: Git - how to list ALL objects in the database
Old solution: Only works if object is in reflog
To find the string "text" in all local objects:
git log --reflog -Stext
To find the pattern "pattern" in all local objects:
git log --reflog --grep=pattern
This will search through all objects, so it will work even if the commit/branch is deleted. Once an object is removed from the local repository (e.g. through a gc), it will no longer be included in the search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With