Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Update</h3> <pre><code>git ls-tree -r -z --name-only HEAD -- */*.c | xargs -0 -n1 git blame \ --line-porcelain HEAD |grep "^author "|sort|uniq -c|sort -nr </code></pre> <p>I updated some things on the way.</p> <p>for the lazy you can also put this into it's own command:</p> <pre><code>#!/bin/bash # save as i.e.: git-authors and set the executable flag git ls-tree -r -z --name-only HEAD -- $1 | xargs -0 -n1 git blame \ --line-porcelain HEAD |grep "^author "|sort|uniq -c|sort -nr </code></pre> <p>store this somewhere in your path or modify your path and use it like</p> <ul> <li><code>git authors '*/*.c' # look for all files recursively ending in .c</code></li> <li><code>git authors '*/*.[ch]' # look for all files recursively ending in .c or .h</code></li> <li><code>git authors 'Makefile' # just count lines of authors in the Makefile</code></li> </ul> <h2>Original Answer</h2> <p>While the accepted answer does the job it's very slow.</p> <pre><code>$ git ls-tree --name-only -z -r HEAD|egrep -z -Z -E '\.(cc|h|cpp|hpp|c|txt)$' \ |xargs -0 -n1 git blame --line-porcelain|grep "^author "|sort|uniq -c|sort -nr </code></pre> <p>is almost instantaneous.</p> <p>To get a list of files currently tracked you can use</p> <pre><code>git ls-tree --name-only -r HEAD </code></pre> <p>This solution avoids calling <code>file</code> to determine the filetype and uses grep to match the wanted extension for performance reasons. If all files should be included, just remove this from the line.</p> <pre><code>grep -E '\.(cc|h|cpp|hpp|c)$' # for C/C++ files grep -E '\.py$' # for Python files </code></pre> <p>if the files can contain spaces, which are bad for shells you can use:</p> <pre><code>git ls-tree -z --name-only -r HEAD | egrep -Z -z '\.py'|xargs -0 ... # passes newlines as '\0' </code></pre> <p>Give a list of files (through a pipe) one can use xargs to call a command and distribute the arguments. Commands that allow multiple files to be processed obmit the <code>-n1</code>. In this case we call <code>git blame --line-porcelain</code> and for every call we use exactly 1 argument.</p> <pre><code>xargs -n1 git blame --line-porcelain </code></pre> <p>We then filter the output for occurences of "author " sort the list and count duplicate lines by:</p> <pre><code>grep "^author "|sort|uniq -c|sort -nr </code></pre> <h3>Note</h3> <p>Other answers actually filter out lines that contain only whitespaces.</p> <pre><code>grep -Pzo "author [^\n]*\n([^\n]*\n){10}[\w]*[^\w]"|grep "author " </code></pre> <p>The command above will print authors of lines containing at least one non-whitespace character. You can also use match <code>\w*[^\w#]</code> which will also exclude lines where the first non-whitespace character isn't a <code>#</code> (comment in many scripting languages).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload