4

I would like to see statistics telling me which authors have contributed how many lines within a given directory.

git-extras and some other similar tools exist, but I am having trouble figuring out if I can use them (or anything else) to restrict my statistics to a given directory.

Any ideas?

davidtheclark
  • 4,666
  • 6
  • 32
  • 42

2 Answers2

8

You can use a short script:

#!/bin/bash

git shortlog -s -- $1 | cut -c8- | while read i
do
    git log --author="$i" --pretty=tformat: --numstat -- $1 \
    | awk -v name="$i" '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "%s: added lines: %s removed lines: %s total lines: %s\n", name, add, subs, loc }'
done

call it loc.sh and then run: loc.sh [directory/file]

The output would be something like this:

Name1: added lines: 10757 removed lines: 49 total lines: 10708
Nmae2: added lines: 1193 removed lines: 94255 total lines: -93062

see more here and here

Community
  • 1
  • 1
Chananel P
  • 1,704
  • 1
  • 18
  • 19
  • Does this restrict the output to a single directory within the repository, or will the stats relate to the whole repository? If it does not, can you make it? — that's one of the keys to the question. If it does, which part does that? – davidtheclark Apr 26 '16 at 01:51
  • 1
    Yes it does. When you run the script loc.sh give it as an argument in cmdline the desired file/directory. (You can see in the script itself "-- $1" this makes the git command filter on the required file/dir) – Chananel P Apr 26 '16 at 07:47
  • 1
    Confirmed! Thanks --- now I'll have to research the way you're using bash so I can better understand it. – davidtheclark Apr 26 '16 at 13:48
-2

check this CLI tool (https://www.npmjs.com/package/whodid)

$ npm install whodid -g

then, go to your project directory and just type this

$ cd my-project
$ whodid

and also you can get result as JSON

$ whodid author --as-json=true

and if you want, not recommanded, but you can include lines in merge commit.

$ whodid author --include-merge=true

and if you feel someones score is too much, you can check the reason with 'heavy' sub-command.

$ whodid heavy --num2=20 --author="jeff <jeff@xahoo.com>"
victor.cheval
  • 157
  • 1
  • 2