统计 Git 代码提交行数

1
$ git log --all --no-merges --shortstat --since="2019-06-30" --pretty=format:'%an %ae' | node ../fe-boss-v2/git-stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

let stats = {};
var isFirstLineOfCommit = true;
var authorName;
rl.on('line', function(line) {
if (isFirstLineOfCommit && line) {
authorName = line.split(' ')[0];
stats[authorName] = stats[authorName] || {filesChanged: 0, insertions: 0, deletions: 0};
}
var match = line.match(/(\d+) files{0,1} changed, (\d+) insertions\(\+\), (\d+) deletions\(-\)/);
if (match !== null) {
stats[authorName].filesChanged += parseInt(match[1], 10);
stats[authorName].insertions += parseInt(match[2], 10);
stats[authorName].deletions += parseInt(match[3], 10);
}
isFirstLineOfCommit = line === '';
}).on('close', () => {
console.log(stats);
});

References

读后有收获可以请作者喝杯咖啡