# git-log-simple-quick **Repository Path**: brokenheart/git-log-simple-quick ## Basic Information - **Project Name**: git-log-simple-quick - **Description**: 基于 Go Fiber 的 Git 日志查询工具,支持快速获取多个 Git 仓库的提交记录。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-13 - **Last Updated**: 2026-02-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Git Log Tool 基于 Go Fiber 的 Git 日志查询工具,支持快速获取多个 Git 仓库的提交记录。 ## 功能特性 - **多仓库并发查询** - 同时查询多个 Git 仓库,自动并发处理 - **每个仓库独立配置** - 支持为每个仓库单独设置分支和作者 - **配置文件热加载** - 配置文件修改后自动生效,无需重启服务 - **灵活过滤** - 支持按作者、日期范围、分支过滤 - **RESTful API** - 提供完整的 HTTP 接口 - **CLI 命令行模式** - 直接执行输出日志,无需启动服务 - **新旧格式兼容** - 支持新的仓库配置格式和旧的路径列表格式 ## 项目结构 ``` git-log-simple-quick/ ├── api/ # HTTP API 处理器和路由 │ ├── handler.go # API 处理器 │ └── router.go # 路由配置 ├── config/ # 配置管理 │ └── config.go # 配置结构、热加载管理器 ├── git/ # Git 操作核心 │ └── git.go # Git 仓库操作 ├── service/ # 业务逻辑层 │ └── service.go # 日志服务 ├── main.go # 程序入口 ├── config.example.json # 示例配置文件 ├── run-cli.bat # CLI 快捷执行脚本 └── go.mod # Go 模块定义 ``` ## 安装 ```bash # 克隆项目 git clone cd git-log-simple-quick # 安装依赖 go mod download # 编译 go build -o git-log-tool.exe ``` ## 配置文件 ### 新格式(推荐) 支持为每个仓库单独配置分支和作者: ```json { "hot_reload": true, "repository_configs": [ { "path": "C:/projects/project-a", "branches": ["main", "develop"], "authors": ["张三", "李四"] }, { "path": "C:/projects/project-b", "branches": ["master"] }, { "path": "C:/projects/project-c" } ], "authors": ["默认作者"], "start_date": "2024-01-01", "end_date": "2024-12-31", "branches": ["main"], "max_count": 100, "output_format": "json", "commit_fields": ["message", "branch", "repository", "date"], "date_format": "2006-01-02 15:04:05" } ``` ### 旧格式(兼容) ```json { "repositories": [ "C:/projects/project-a", "C:/projects/project-b" ], "authors": ["张三"], "start_date": "2024-01-01", "end_date": "2024-12-31", "branches": ["main"], "max_count": 100 } ``` ### 配置说明 | 字段 | 类型 | 说明 | |------|------|------| | hot_reload | bool | 是否启用配置文件热加载 | | repository_configs | array | 仓库配置列表(新格式) | | repository_configs[].path | string | 仓库路径 | | repository_configs[].branches | array | 该仓库的分支列表,为空使用全局配置 | | repository_configs[].authors | array | 该仓库的作者列表,为空使用全局配置 | | repositories | array | 仓库路径列表(旧格式,兼容) | | authors | array | 全局作者过滤列表 | | start_date | string | 开始日期,格式:2006-01-02 | | end_date | string | 结束日期,格式:2006-01-02 | | branches | array | 全局分支列表 | | max_count | int | 最大返回记录数,0 不限制 | | output_format | string | 输出格式:json, text | | commit_fields | array | 提交记录显示字段:hash, short_hash, author, email, date, message, branch, repository | | date_format | string | 日期显示格式,默认:2006-01-02 15:04:05 | ## 使用 ### CLI 命令行模式(推荐) 直接执行获取日志,无需启动 HTTP 服务: ```bash # 默认输出 JSON 格式到控制台 ./git-log-tool.exe -cli # 使用指定配置文件 ./git-log-tool.exe -cli -config test-config.json # 输出为 text 格式 ./git-log-tool.exe -cli -format text # 输出到文件 ./git-log-tool.exe -cli -output logs.json # 组合使用 ./git-log-tool.exe -cli -config test-config.json -format text -output logs.txt ``` #### CLI 参数说明 | 参数 | 说明 | |------|------| | -cli | 启用 CLI 模式,直接输出日志而不启动 HTTP 服务 | | -config | 配置文件路径,默认 config.json | | -output | 输出文件路径,为空则输出到控制台 | | -format | 输出格式:json 或 text,默认使用配置文件中的设置 | #### 快捷执行 双击 `run-cli.bat` 即可快速执行 CLI 模式,输出 text 格式日志。 ### HTTP 服务模式 启动 Web 服务,通过 API 获取日志: ```bash # 使用默认配置(config.json) ./git-log-tool.exe # 指定配置文件和端口 ./git-log-tool.exe -config myconfig.json -port 8080 ``` #### 服务参数说明 | 参数 | 说明 | |------|------| | -config | 配置文件路径,默认 config.json | | -port | 服务端口,默认 3000 | ### API 接口 #### 健康检查 ```bash GET /api/v1/health ``` #### 获取日志 ```bash # 使用配置文件的默认设置 GET /api/v1/logs # 自定义参数查询 GET /api/v1/logs?authors=张三&start_date=2024-01-01&max_count=50 # 查询特定分支 GET /api/v1/logs?branches=main&branches=develop ``` #### 获取仓库列表 ```bash GET /api/v1/repositories ``` 返回示例: ```json { "repositories": [ { "path": "C:/projects/project-a", "valid": true, "branches": ["main", "develop", "feature/login"], "configured_branches": ["main", "develop"], "authors": ["张三", "李四", "王五"], "configured_authors": ["张三", "李四"] } ] } ``` #### 获取配置 ```bash GET /api/v1/config ``` #### 更新配置(运行时) ```bash PUT /api/v1/config Content-Type: application/json { "repository_configs": [ { "path": "C:/projects/project-a", "branches": ["main"], "authors": ["张三"] } ], "hot_reload": true } ``` #### 重新加载配置 ```bash POST /api/v1/config/reload ``` #### 保存配置到文件 ```bash POST /api/v1/config/save?path=config.json ``` ## 热加载说明 当 `hot_reload` 设置为 `true` 时: 1. 服务会每 2 秒检查一次配置文件是否有修改 2. 文件修改后自动重新加载配置 3. 新的配置会立即生效,无需重启服务 4. 控制台会输出 "配置已热加载" 的提示 如果热加载被禁用,可以通过 API 手动重新加载: ```bash POST /api/v1/config/reload ``` ## 优先级规则 查询日志时的配置优先级(从高到低): 1. **API 请求参数** - 如 `?authors=张三&branches=main` 2. **仓库特定配置** - 该仓库在 `repository_configs` 中设置的 `branches` 和 `authors` 3. **全局配置** - 配置文件中的 `branches` 和 `authors` ## PowerShell 测试示例 ```powershell # 健康检查 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/health" -Method GET # 获取配置 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/config" -Method GET # 获取日志 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/logs?max_count=10" -Method GET # 更新配置 $body = @{ repository_configs = @( @{ path = "C:/projects/my-repo" branches = @("main", "develop") authors = @("张三") } ) hot_reload = $true } | ConvertTo-Json -Depth 10 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/config" -Method PUT -Body $body -ContentType "application/json" # 重新加载配置 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/config/reload" -Method POST # 保存配置 Invoke-RestMethod -Uri "http://localhost:3000/api/v1/config/save" -Method POST ``` ## 技术栈 - [Go](https://golang.org/) 1.21+ - [Fiber](https://gofiber.io/) v2 - Web 框架 - Git 命令行工具 ## 许可证 MIT