Skip to content

Instantly share code, notes, and snippets.

@NikhilVerma
Created March 17, 2021 20:15
Show Gist options
  • Save NikhilVerma/cdadb7d72bf332b151c96226cddfd214 to your computer and use it in GitHub Desktop.
Save NikhilVerma/cdadb7d72bf332b151c96226cddfd214 to your computer and use it in GitHub Desktop.
This gist is a fast way to get line contributions in git per author.
########################################################################
# This gist is a fast way to get line contributions in git per author. #
# The results should not be intepreted seriously, line-contributions #
# are a weak indicator of the value of someone's contribution. #
########################################################################
# If you have GNU parallel utility installed (recommended)
git ls-tree --name-only -r HEAD | parallel --eta "git blame -w -M -C --line-porcelain {} | grep \"^author \"" | sort -S 20G | uniq -c | sort -nr
# If you don't have GNU parallel utility installed
git ls-tree --name-only -r HEAD | xargs -n1 git blame -w -M -C --line-porcelain | grep "^author " | sort -S 20G | uniq -c | sort -nr
###############################
# Explanation of the commands #
###############################
# List all the files found in the git HEAD for that directory
git ls-tree --name-only -r HEAD
# For each line find the user who authored it, ignoring whitespaces, and detecting copy-pastes
git blame -w -M -C --line-porcelain
# Extract the author field
grep "^author "
# Sort ALL the author fields (20G is the memory buffer allowed for sorting)
sort -S 20G
# Count unique lines
uniq -c
# Sort them one more time from their counts
sort -nr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment