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.

3
  • Can you defined your metric? What does "how much" means? LOC? Commented Apr 3, 2013 at 17:30
  • Lines of Code would be a good metric. Commented Apr 3, 2013 at 17:31
  • 1
    almost - it needs a tweak to work for this question, though Commented Apr 3, 2013 at 17:41

3 Answers 3

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.

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

1 Comment

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
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.

3 Comments

Date would have been more useful with the days or months component greater than 12 to illustrate the format.
Fair point. For reference, the format used is DD/MM/YYYY, and YYYY-MM-DD also works.
Don't you need the --no-merges flag in the git log to avoid duplicates?
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.