Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to estimate a contribution of a person to my project in terms of added/changed lines of code?

Tags:

git

I have a GIT repository and I want to calculate how many lines of code were added/changed by one person or a group of persons during some period of time. Is it possible to calculate with git?

like image 870
Lu4 Avatar asked Jan 04 '11 11:01

Lu4


People also ask

How do I see contributions on GitHub?

Whenever you commit to a project's default branch or the gh-pages branch, open an issue, or propose a Pull Request, we'll count that as a contribution. Repositories are sorted by your recent impact. A commit today is worth more than a commit last week.


2 Answers

You can use git log and some shell-fu:

git log --shortstat --author "Aviv Ben-Yosef" --since "2 weeks ago" --until "1 week ago" \     | grep "files\? changed" \     | awk '{files+=$1; inserted+=$4; deleted+=$6} END \            {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}' 

Explanation: git log --shortstat displays a short statistic about each commit, which, among other things, shows the number of changed files, inserted and deleted lines. We can then filter it for a specific committer (--author "Your Name") and a time range (--since "2 weeks ago" --until "1 week ago").

Now, in order to actually sum up the stats instead of seeing the entry per commit, we do some shell scripting to do it. First, we use grep to filter only the lines with the diffs. These lines look like this:

 8 files changed, 169 insertions(+), 81 deletions(-) 

or this:

 1 file changed, 4 insertions(+), 4 deletions(-) 

We then sum these using awk: for each line we add the files changed (1st word), inserted lines (4th word) and deleted lines (6th word) and then print them after summing it all up.

Edit: forward slashes were added in the top snippet so it can be copy and pasted into a command line.

like image 108
abyx Avatar answered Oct 06 '22 00:10

abyx


You can generate stats using Gitstats. It has an 'Authors' section which includes number of lines add/removed by the top 20 authors (top 20 by commit count).

Edit: There's also Git: Blame Statistics

like image 38
Dogbert Avatar answered Oct 06 '22 01:10

Dogbert