5

I'm looking for a command to execute against my git repo to discover the amount of code changed in a certain period of time.

I want to know how much code was changed since day 'X'. I don't really care about the percentage of code changed by each author.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
MatheusJardimB
  • 3,599
  • 7
  • 46
  • 70

3 Answers3

6

You can use the --stat option of git diff.

For instance

git diff --stat HEAD HEAD~1

will tell you what changed from the last commit, but I think what's closest to your request is the command

git diff --shortstat HEAD HEAD~1

which will output something like

524 files changed, 1230 insertions(+), 92280 deletions(-)

EDIT

Actually I found this great answer that addresses the same issue much better that I can do.

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
  • this only outputs the no of lines added and deleted, but it there can be modified line too,. Modify means, in *old commit* `This is me` line is changed to `this is me` in the new commit. Is there a way to get the no of lines modified in a repo between commits – Kasun Siyambalapitiya Dec 07 '16 at 12:09
5

Following up the excellent answer Gabriele found, the exact command you need is:

git log --since=31/12/2012 --numstat --pretty="%H" | awk '
    NF==3 {plus+=$1; minus+=$2;}
    END   {printf("+%d, -%d\n", plus, minus)}'

(yes, you can paste that onto a single line, but the answer's more readable like this)

The key difference is the in a certain period of time requirement, handled by the --since argument.

Useless
  • 64,155
  • 6
  • 88
  • 132
1

As a less awksome alternative:

REV=$(git rev-list -n1 --before="1 month ago" master)
git diff --shortstat $REV..master

The "before" date can of course be a more standard representation of time as well.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54