total original lines of code from entire git repository history

99 Views Asked by At

Is there a way to stat the total number of lines added/removed/modified in a git repository? A number of posts give answers for "how many loc is this project at at a certain commit" by analyzing the files in it, it doesn't give a feel for just how many different things have been tried and abandoned and changed during the whole life of the project. And just checking out every single commit and stating that and summing that wouldn't make sense either, because there's usually quite a bit of redundancy from commit to commit.

1

There are 1 best solutions below

0
Aram Maliachi On

Can't think of something at a repo level but the following can work at a branch level:

Option 1:

git diff --shortstat $(git rev-list --max-parents=0 HEAD) @

Example output:

9 files changed, 273 insertions(+), 4 deletions(-)

or

git diff --numstat $(git rev-list --max-parents=0 HEAD) @

Example output (detailed by line insertions and line deletions per file):

10      4       rest-api.ps1 => auditlog.ps1
15      0       azlabshow.ps1
34      0       create-pr.ps1
26      0       get-build-time.ps1
25      0       getchangesets.ps1
42      0       listreleases.ps1
40      0       listusers-csv.ps1
43      0       merge-refs.ps1
38      0       testplans(outcome).ps1

Used git diff by diffing HEAD (@) with the initial commit. Use bash.