Git Repo’s Useful Statistics
Use these git commands to find the top largest source files by number of lines, the top contributors by # of commits, the top contributors by # of lines, the composition of source files by programming language lines and other useful information you can extract from your Git Repository
Find Total Code Lines Tracked By Git?
This command shows the total number of lines in the HEAD of your Git Repository
git ls-files | xargs cat | wc -l
Example Output:
8237 # Total Number of Lines in Git Repo
Find Total Lines In /test
Folder for Git Repo?
Find the total lines in the test/ folder of your git repository
git ls-files --directory test/ | xargs cat | wc -l
Number of lines in Git Repository files per Author?
This command lists the number of lines contributed by each author in this Git repository. (Assumes you have ruby installed).
git ls-files -z | xargs -0n1 git blame -w | ruby -n -e '$_ =~
/^.*\((.*?)\s[\d]{4}/; puts $1.strip' | sort -f | uniq -c | sort -nr
Find N Largest Files In a Git Repo?
Finds the largest 15 files in your git repository with the highest number of lines.
wc -l $(git ls-files) | sort -nr | head -15
Find Number of Git Commits Per Author From the Beginning Of Time?
Find the total number of commits per author sorted by most commits first.
git shortlog -s -n
Find Lines Of Code By Programming Language?
Get the number of lines in your Git Repo per programming language. For this to work you’ll need to install cloc first using brew install cloc
then run the following:
cloc $(git ls-files)
Example output:
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
Python 79 1861 2025 5029
YAML 11 81 8 778
Markdown 3 55 0 102
reStructuredText 1 6 2 8
Bourne Again Shell 1 10 27 6
--------------------------------------------------------------------------------
SUM: 95 2013 2062 5923
--------------------------------------------------------------------------------
Any else you can think of? Please leave me a comment and I can amend it to this article.
References:
https://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
https://stackoverflow.com/questions/1265040/how-to-count-total-lines-changed-by-a-specific-author-in-a-git-repository