Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to measure the amount of code changed in a period of time? [duplicate]

Tags:

git

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.

like image 945
MatheusJardimB Avatar asked Apr 03 '13 17:04

MatheusJardimB


People also ask

How do you count the number of commits?

Solution: To get the number of commits for each user execute git shortlog -sn --all. To get the number of lines added and delete by a specific user install q and then execute: git log --author="authorsname" --format=tformat: --numstat | q -t "select sum(c1), sum(c2) from -"

Which command can check the revision history of a repository?

The git log command displays committed snapshots. It lets you list the project history, filter it, and search for specific changes.

How does git calculate diff?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.


3 Answers

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.

like image 51
Gabriele Petronella Avatar answered Oct 03 '22 16:10

Gabriele Petronella


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.

like image 29
Useless Avatar answered Oct 03 '22 16:10

Useless


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.

like image 33
Jussi Kukkonen Avatar answered Oct 03 '22 15:10

Jussi Kukkonen