Created
September 23, 2020 20:04
-
-
Save jcaxmacher/ea972b336474bcfef52a73b77a4a7c06 to your computer and use it in GitHub Desktop.
Git blame and comment in every file
This file contains hidden or 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
#!/bin/bash | |
for file in $(git ls-files); do | |
commits=`git blame $file | cut -f1 -d' ' | sort -u` | |
count=`git blame $file | cut -f1 -d' ' | sort -u | wc -l` | |
comments="" | |
for commit in $commits; do | |
newcommit=`echo $commit | sed -e 's/^\^//g'` | |
user=`git show -s --format='%an' $newcommit` | |
dt=`git show -s --format=%ci $newcommit` | |
message=`git log --format=%B -n 1 $newcommit` | |
lines=`git blame $file | grep "^$commit" | cut -d '(' -f 2- | cut -d ')' -f 1 | grep -o '[^ ]*$'` | |
newlines="" | |
for line in $lines; do | |
newlines="$newlines,$((line + count))" | |
done | |
comments="${comments}# $dt - $user - $message - lines:$newlines\n" | |
done | |
echo -e "${comments}$(cat $file)" > $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment