# git_analysis **Repository Path**: k9s/git_analysis ## Basic Information - **Project Name**: git_analysis - **Description**: git_analysis - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-11 - **Last Updated**: 2026-03-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # git_analysis 用于统计 GitLab 仓库指定分支的代码指标,支持两种模式: - `lines-total`:统计当前代码总行数 - `yearly-change`:统计某一年新增行数与删除行数 分支选择固定为:优先 `master`,不存在再尝试 `main`,仍不存在则回退默认分支。输出: - `git_analysis.csv`:全部仓库统计结果 ## 使用方式 1. 生成 GitLab Personal Access Token(建议 `read_api` + `read_repository` 权限) 2. 编译二进制 ```bash go build -ldflags "-s -w" -o git_analysis . ``` 3. 运行并输出汇总: ```bash export GITLAB_TOKEN='你的token' ./git_analysis \ -base-url 'https://git.xxx.cn' \ -output-dir './output' \ -workers 6 \ -stat-mode lines-total ``` 按年份统计增删变化量示例: ```bash ./git_analysis \ -base-url 'https://git.xxx.cn' \ -output-dir './output' \ -workers 6 \ -stat-mode yearly-change \ -stat-year 2025 \ -limit 200 ``` 默认会导出到: - `stat-mode=lines-total`:`./output/lines-total.csv` - `stat-mode=yearly-change -stat-year=2025`:`./output/yearly-change_2025.csv` 可选参数: - `-group-id`:只统计某个 group(含子组) - `-per-page`:API 分页大小,默认 `100` - `-skip-archived`:是否跳过归档仓库,默认 `true` - `-timeout-seconds`:API 超时秒数,默认 `30` - `-stat-mode`:统计模式,支持 `lines-total`、`yearly-change`(兼容 `total`、`change`) - `-stat-year`:按年统计变化量时的目标年份,默认当前年 - `-limit`:最多处理多少个仓库,默认 `0` 表示不限制输出字段 ## 说明 - 空仓库判定基于远端分支列表:无任何 heads 分支即标记 `is_empty=true` - 运行时会实时打印进度日志 - 统计时优先使用 `master`,不存在再尝试 `main`,仍不存在则回退到默认分支;都不存在则 `error=master/main/default branch not found` - 克隆失败或权限不足会写入 `error` 字段 - `stat-mode=lines-total` 时:递归检测所有层级目录(仅跳过 `.git`),并过滤常见二进制文件后统计 `line_count` - `stat-mode=yearly-change` 时:按 `stat-year` 汇总 `added` 与 `deleted`