Git: How to get a list of users and how many lines of code they've written

I wrote/stole a script some time ago to find out the current “owner” of a particular file that’s in a Git repo.

git blame --line-porcelain "$@" | sed -n 's/^author //p' | sort | uniq -c | sort -rn

It shows the results from git blame and sorts it by how many lines each user has modified.

  • GIT: how can I watch for local changes in a performant way?
  • Git and KDevelop
  • How do I check if a repository is bare?
  • How do I rename a repository on GitHub?
  • Managing development of 2+ nodejs packages with dependencies
  • Git push fails with “fatal: early EOF” when PUSHing but only on one file
  • The result looks something like this:

     125 Joe
      16 Fred
      16 Alice
       7 Jane
       4 Bob

    My question is, how can I modify this script to recurse over an entire repo as opposed to a single file?

  • git & Cygwin - trailing whitespace causes “not uptodate”
  • get list of git branches for a repo hosted on github
  • Is there equivalent of git Revert/cherry-pick for Hg?
  • View .docx file on Github and use git diff on .docx file format
  • Git: Get all notes of a branch
  • SSH Agent Forwarding with Ansible
  • One Solution collect form web for “Git: How to get a list of users and how many lines of code they've written”

    You can list all files in Git using git ls-tree.

    The following does what your script does, but over all files on the master branch.

    git ls-tree -r master --name-only | xargs -I {} git blame --line-porcelain {} | sed -n 's/^author //p' | sort | uniq -c | sort -rn
    Git Baby is a git and github fan, let's start git clone.