統(tǒng)計代碼行數(shù)
- 按author統(tǒng)計一段時間內的所有提交的行數(shù)
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'; done
- 統(tǒng)計文檔以外的代碼行數(shù),下面忽略.md和.org文件格式文件
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --author="$name" --pretty=tformat: --numstat | awk '!/(\.md$|\.org$)/ { add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'; done
- 排除doc和docs兩個文件夾的統(tǒng)計
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --author="$name" --pretty=tformat: --numstat | awk 'NR==FNR && /doc|docs/ { excluded[$0]++; next } !($0 in excluded) { add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", int(add), int(subs), int(loc) }' - <(find . -path "./doc" -prune -o -path "./docs" -prune -o -type f -print); done
4 只統(tǒng)計某些類型的文件
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --author="$name" --pretty=tformat: --numstat | grep "\(|.clj\|.cljs\|.js\|.ts\|.css\|.vue\|.scss\|.java\|.sql\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
- 增加文件夾過濾蔬浙,比如統(tǒng)計src目錄下的,同時排除md文件和org文件
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --pretty=tformat: --numstat -- src/ | awk '!/(\.md$|\.org$)/ { add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", int(add), int(subs), int(loc) }'; done
統(tǒng)計代碼提交次數(shù)
以下統(tǒng)計淆党,前20名成員commit次數(shù)
git log --after="2023-01-01 00:00:00" --before="2023-03-31 23:59:59" --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 20
統(tǒng)計文件修改頻次
git log --after="2022-01-01 00:00:00" --before="2023-03-31 23:59:59" --pretty=format: --name-only | grep -v '^$' | sort | uniq -c | sort -rn | head -n 10