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
  • 104,800
  • 21
  • 210
  • 229
MatheusJardimB
  • 3,431
  • 6
  • 44
  • 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
  • 104,800
  • 21
  • 210
  • 229
  • 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
  • 59,916
  • 5
  • 82
  • 126
  • Date would have been more useful with the days or months component greater than 12 to illustrate the format. – funkybro May 16 '19 at 08:12
  • Fair point. For reference, the format used is `DD/MM/YYYY`, and `YYYY-MM-DD` also works. – Useless May 16 '19 at 11:35
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,141
  • 1
  • 33
  • 51