This script can do the job:
#!/bin/bash # Invoke as repodetails.bash /path/to/git/repo git_repo_path=$1 cd $git_repo_path echo "" > output.txt # Get a list of tracked files in the current repository. file_list=$(git ls-tree -r HEAD --name-only) for file in $file_list do # Get the count of commits by listing the commit history of the file. commit_count=$(git log --oneline -- "$file" | wc -l) # Use wc on the file to get the word count. word_count=$(git show "HEAD:$file" | wc -w) # Use the summary option of git shortlog to get a list of contributors. author_count=$(git shortlog -s $file | wc -l) echo "$file $commit_count $word_count $author_count" >> output.txt done
As an example, I made a clone of this repo from GitHub: https://github.com/GitSquared/edex-ui to the /opt directory. Then, I ran my script as ./repodetails.bash /opt/edex-ui. This generated a file named output.txt under /opt/edex-ui.
The output.txt file contains the required details in the following format:
src/classes/modal.class.js 2 165 1 src/classes/netstat.class.js 8 305 1 src/classes/ramwatcher.class.js 5 257 2 src/classes/sysinfo.class.js 6 291 1 src/classes/terminal.class.js 31 906 2 src/classes/toplist.class.js 2 95 1 src/classes/updateChecker.class.js 4 190 1 src/package-lock.json 55 685 3 src/package.json 68 65 5 src/ui.html 20 161 1