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 submodule update gives “error: invalid key (newline)”
  • Succinctly specify exact state of git repository
  • How to find branch whose commit have been merged or rebased
  • Get rid of foreign git branch
  • How to convert git branches to mercurial named branches?
  • How do I delete local remote-tracking branches when remote branch is deleted?
  • 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?

  • Finding the SHA1's of all objects in a commit git
  • Can “git pull --all” update all my local branches?
  • git log --follow -L280,+20:foo.c --> git logs can only follow renames on one pathname at a time
  • Does Git, SVN, etc do this type of “branching & merging” or something like this?
  • What will happen to uncommited and unstaged files after git reset --hard?
  • Best way to setup mirror for Gerrit and all of its Git repos
  • 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.