OK, to expand on the accepted answer…
As to finding all commits with pathnames, then the only thing the script in the accepted answer does not do for you is printing the pathname. But fear not—it's easy to modify.
If you go to a nearby Git repository and run git ls-tree -r HEAD
you'll see that this command dumps the whole tree hierarchy referenced by the named commit (HEAD
in our case)—with both SHA-1 names and "normal" filenames. The script from the answer just grep
s this output to find the SHA-1 name and ignores the rest.
So we can modify it to read:
#!/bin/sh
obj_name="$1"
shift
git log "$@" --pretty=format:'%T %h %s' \
| while read tree commit subject ; do
git ls-tree -r "$commit" | while read _ _ sha name; do \
if [ "$sha" == "$obj_name" ]; then
echo "$sha\t$name"
break
fi
done
done
…and it will now also print the name of the file associaled with the target blob along with the commit name.