工具

hercules

go,维护良好,较为复杂,可以尝试

https://github.com/src-d/hercules

gitinspector

Python 但是最后一次维护是Oct 19, 2020,不能在py3下运行,可以尝试

https://github.com/ejwa/gitinspector

git-stats

合并程序是二进制,输出是js,不好改造

https://github.com/IonicaBizau/git-stats

git-quick-stats

written by shell(不太好改造),持续有维护,可以尝试

https://github.com/arzzen/git-quick-stats#macos-homebrew

brew install git-quick-stats

You can use the Docker image provided:

Build: docker build -t arzzen/git-quick-stats .
Run interactive menu: docker run --rm -it -v $(pwd):/git arzzen/git-quick-stats
Docker pull command: docker pull arzzen/git-quick-stats docker repository
docker run --rm -it -e _GIT_SINCE="2017-01-20" -v $(pwd):/git arzzen/git-quick-stats -j

统计

代码量

不鼓励卷这个绩效,需要自取

#!/bin/bash
# README
# 1. 找一个目录git clone  $repos 中定义的目录
# 2. 查看各个仓库自己提交过的作者名
# 3. branches 规则 ${repo}_branches,合并过的分支请选择最新的即可,反着会重复统计

repos=("python" "php" "go")
authors=("peter" "pe")
start_date="2024-01-01"
end_date="2024-03-31"

python_branches=("dev" "master")
php_branches=("dev", "master")
go_branches=("master" "dev")

# 目前是按格式匹配,根据需要调整
include="-- \"*.py\" \"*.go\" \"*.php\" \"*.sh\""
# 默认排除了 go 的 vendor 目录,其他根据需要调整
exclude="':(exclude)vendor/'"

# print csv header
echo "Repo,Author,Branch,Files Changed,Lines Inserted,Lines Deleted" > stats.csv

function count_changes {
    author=$1
    branch=$2
    repo=$3
    git checkout $branch && git pull --ff
    git_log_commit="git log --pretty=oneline --shortstat --since=\"$start_date\" --until=\"$end_date\" --author=\"$author\" $include $exclude $branch"
    echo "excuting: $git_log_commit"
    stats=$(eval "$git_log_commit" | grep -E 'files? changed' | awk -v author=$author '{files+=$1; inserted+=$4; deleted+=$6} END {print files, ", ", inserted, ", ", deleted}')
    # print csv data row
    echo "$repo, $author, $branch, $stats" >> ../stats.csv
}

for repo in "${repos[@]}"; do
    echo $repo
    pushd $repo
    branch_var="${repo}_branches[@]"
    for branch in "${!branch_var}"; do
        echo $branch
        for author in "${authors[@]}"; do
            count_changes "$author" "$branch" "$repo"
        done
    done
    popd && pwd
done