Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Git statistics about line contributions within specific directories

Tags:

git

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?

like image 949
davidtheclark Avatar asked Oct 27 '25 06:10

davidtheclark


1 Answers

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

like image 121
Chananel P Avatar answered Oct 28 '25 20:10

Chananel P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!