Add get_blob and get_commit_for_blob

This commit is contained in:
Gerhard Hoffmann 2022-06-25 17:18:13 +02:00
parent e5e6c4c1cd
commit f8c091ad0c

View File

@ -224,4 +224,20 @@ changed_file_names () {
"while in $PWD"
fi
}
# fi
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
blob=$(get_blob $1)
if [ ! -z $blob ]; then
# search for the blob in all commits for the file(name) $1
echo $(echo $(git log --all --pretty=format:%H -- $1) |
xargs -I{} sh -c "git ls-tree {} -- $1 |
grep -q $blob && echo {}")
fi
}