Skip to content

Instantly share code, notes, and snippets.

@dstd
Created January 30, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstd/0ef8c01c27a54e3adf5be59f0035157f to your computer and use it in GitHub Desktop.
Save dstd/0ef8c01c27a54e3adf5be59f0035157f to your computer and use it in GitHub Desktop.
Find specific file in GIT history
#!/usr/bin/env bash
# Find specific file in GIT history
if [ "$1" = "" ]; then
echo "Usage: ./$(basename ${0}) file" && exit 1
fi
_file=$1
blob=`git hash-object $_file`
if [ "$blob" == "" ]; then
echo "$_file is not a readable file" && exit 1
fi
echo "Search for blob $blob"
git rev-list --all |
while read commit; do
found=`git ls-tree -r $commit | grep $blob`
if [ "$found" != "" ]; then
echo "--------------- $commit: `git log -n 1 --pretty=format:"%ad –– %s" $commit`"
echo "$found"
echo ""
fi
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment