Created
January 30, 2019 11:23
-
-
Save dstd/0ef8c01c27a54e3adf5be59f0035157f to your computer and use it in GitHub Desktop.
Find specific file in GIT 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
#!/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