Skip to content

Instantly share code, notes, and snippets.

@banyudu
Last active April 12, 2023 02:24
Show Gist options
  • Save banyudu/0735ede0b9236751b4dea4c733fc7b91 to your computer and use it in GitHub Desktop.
Save banyudu/0735ede0b9236751b4dea4c733fc7b91 to your computer and use it in GitHub Desktop.
Generate git commit sha for every line of code in given file
#!/bin/bash
# Check if a filename was provided as an argument
if [ -z "$1" ]; then
echo "Usage: git blame-all filename"
exit 1
fi
# Loop through each line of the given file and run git blame
line_number=1
while read line; do
commit_sha=$(git blame -L $line_number,$line_number "$1" | cut -c -8)
#echo "$line_number: $commit_sha"
echo "$commit_sha" : "$line"
line_number=$((line_number+1))
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment