Code churn for git repository?

Viewed 4129

I am trying to get code churn metric for a single file in my git repository. I came across a tool called codemaat (https://github.com/adamtornhill/code-maat) to calculate code churn from git logs. When I run it against the log file it gave me

$ docker run --rm -v /home/user/Documents/codestatisticsVCS/code-maat-master:/codemaat code-maat -l /codemaat/pmygit.log -c git2 -a abs-churn
date,added,deleted,commits
2012-11-27,36,98,4
2012-12-10,24,0,2
2013-05-30,1,1,1
2014-02-14,10,21,1
2014-04-17,8,2,1
..
.. so on

The question is two parts: (1) I was thinking that the code churn metric is single value for a git file, here it gives me a list of added, deleted and commits, so is my understanding correct or not correct, what is the exact formula? (2) Next question is about added, deleted and commits, what do they represent? why commits is 2 or 4, do we want to club?

1 Answers

Code maat is used for commits not a file. And you can also find the input data (git log --pretty=format:'[%h] %aN %ad %s' --date=short --numstat --after=YYYY-MM-DD in the link you showed) is the commits you specified.

If you only need to analyze data for a file in git repo, the workaround is move the file to another repo and then use code maat to analyze the new git repo.

The way to move the file to a new git repo as below:

git clone URL
cd gitrepo
git remote rm origin
git filter-branch -f --prune-empty --index-filter "git rm --cached --ignore-unmatch $(git ls-files | grep -v 'filename)"
#view the commit history to check if the old history is replaced totally

Now all the commits are only track the changes only for the file (filename in above command), you can specify the commits to analyze for the file.

Related