git statistics on commit based level

55 views Asked by At

I would like to get a custom statistics on git repository on commit based level on specific branch. For instance, I'm interested to find how the TODOs comments evolve during the time since the first commit. I.e. I have to look at worktree at each commit and run some script that will do the stat collecting (counting the TODOs). How can I do such things? Maybe there's better approach that can scan only increment from commit data rather then scanning full worktree every time?

1

There are 1 answers

0
Lucas Oshiro On

You can use git log -S or git log -G. From the git log manpage:

       -S<string>
           Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file.

       -G<regex>
           Look for differences whose patch text contains added/removed lines that match <regex>.

You can use them with other git log options, such as -p, and you can also specify a branch and a file. For example:

git log -p -S 'TODO' my_branch -- my_code.c

This will list all the commits that changed the number of occurrences of TODO in my_code.c on branch my_branch, and print what changes were introduced on each of those commits.