tags:

views:

37

answers:

2

Hi everyone,

I was wondering if there is any tools out there that can report on the LOC for Added, Modified and Deleted code from a GIT check in.

It would be awesome if it could then add the count to a some sort of DB

A: 

git show --stat <commit> displays changed files, insertions and deletions per-file, and totals. If you want to call this from a script, you can use --numstat instead which outputs it in a machine-readable format. (You also probably want to add --pretty=oneline, so your script can just skip the first line of output, after which the counts per file will be displayed).

See git help show and git help diff for more information.

mkarasek
Will this only count text lines? I would like to add extra logic into counting lines. For example only count lines with '=' or "if" or "else" etc.
ChrisKolenko
This will just count total number of lines added and removed. If you want something more detailed, you'll have to just have git output the diff and have a script that parses it.
mkarasek
A: 

As mkarasek mentions in his answer, any additional logic in git show --stat needs to be scripted.

You can start by having a look at this Python script: GitHub project git-loc.
You could inject some logic when parsing the git log --reverse -p he uses to compute the number of loc.

VonC