16

Is there a simple way I can ask git for the amount of lines I added (or add and removed) in a specific date range?

I'm using git on Windows, Linux and TortoiseGit(Windows)

3
  • 1
    Something both posters seem to have missed is that there's a --numstat option, which gives a much more machine-readable format than --stat. Commented Jun 5, 2011 at 13:23
  • 1
    @Jefromi: What makes you think I missed it? ' 1 files changed, 2 insertions(+), 0 deletions(-)' is no harder to parse in awk than '2 0 .gitconfig' and saves me tallying the number of files changed! Commented Jun 6, 2011 at 2:19
  • Also check out @quorian's great answer which gives counts of lines added, removed and modified. Commented Nov 26, 2013 at 0:33

3 Answers 3

24

Building upon Seth Robertson's answer, (+1 Seth!) awk will tally up the columns for you:

% git log --stat --author $(git config --get user.email) --since="last year" --until="last month" | awk -F',' '/files? changed/ { files += $1 insertions += $2 deletions += $3 print } END { print "Files Changed: " files print "Insertions: " insertions print "Deletions: " deletions print "Lines changed: " insertions + deletions }' 

 

Sign up to request clarification or add additional context in comments.

7 Comments

This seems useful, but how do I invoke this in Terminal? Not familiar with awk.
@WallaceSidhrée: In bash or zsh, you can just past my answer straight in (without the leading % . Or you could put this into a script somewhere in your ${PATH}.
This can yield incorrect results! The summary line of stat may hide deletions or insertions if there are none. If there are no insertions in that particular commit, then git may show 1 file changed, 6 deletions(-), making your script add the deletions to insertions variable.
one could modify the awk script to use matching match($0, /([0-9]+) files? changed(, ([0-9]+) insertions?\(\+\))?(, ([0-9]+) deletions?\(\-\))?/, m); files += m[1]; insertions += m[3]; deletions += m[5];
your answer was definitely correct at the time! the comments in this answer stackoverflow.com/a/13056003/804840 indicate that the output changed during a 1.7.9 -> 1.7.10 patch.
|
9
git log --stat --author me --since="last year" --until="last month" 

You can then post-process the --stat information at the bottom.

Comments

2

In case someone is interested in an overall statistics of the repo:

  1. Right click on the repo folder, select TortoiseGit/Show Log.
  2. Click Statistics at the bottom of the dialog. Statistics

Comments