Git提交助手

一个基于MCP协议的本地工具,通过分析Git仓库变更帮助开发者生成专业的提交信息。

  • by tarekbadrsh
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 tarekbadrsh/git-commit-helper

使用说明

Git提交助手

一个MCP(模型上下文协议)服务器,通过读取git存储库信息来帮助Claude编写专业提交消息。使用官方的Anthropic Rust SDK构建,以获得最佳性能和可靠性。

🌟 特性

✨ 独立二进制 -无需Node、Python、Bun或任何运行时依赖项
⚡ 闪电般快速 -在1毫秒内启动
🔒 隐私第一 -完全在本地计算机上运行
🌍 交叉平台的 -适用于Linux、macOS(英特尔和ARM)和Windows
🎯 智能提交消息 -Claude分析您的更改,并提出清晰、常规的提交建议
📦 微小尺寸 -仅约3MB二进制文件
🛠️ 官方SDK -采用Anthropic官方Rust MCP SDK构建,具有可靠性

💡 用例

此工具非常适合:

  • 独立开发者 谁想要一致、专业的承诺信息
  • 团队 维护跨项目的提交消息标准
  • 开源贡献者 为社区项目编写明确的承诺
  • 代码审阅者 谁需要快速了解发生了什么变化
  • Git学习者 谁想看到好的提交消息的例子

🎬 演示

以下是它在实践中的工作原理:

You: I've made some changes and staged them. Can you write me a commit message?

Claude: Let me check what you've staged.
[Uses git_diff_staged tool]

I can see you've added user authentication with JWT tokens and password hashing. 
Here's a suggested commit message:

feat(auth): implement JWT-based user authentication

- Add JWT token generation and verification
- Implement bcrypt password hashing for security
- Create login and registration endpoints
- Add middleware for protected routes

This follows conventional commit format. Want me to adjust anything?

🚀 安装说明

先决条件

你需要安装Rust。如果你没有:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

访问 rustup.rs 更多安装选项。

从源代码构建

  1. 克隆和构建:

    git clone https://github.com/tarekbadrsh/git-commit-helper.git
    cd git-commit-helper
    cargo build --release
    
  2. 查找您的二进制文件:

    # The binary will be at:
    # target/release/git-commit-helper
    
  3. 可选-全局安装:

    # Copy to a directory in your PATH
    sudo cp target/release/git-commit-helper /usr/local/bin/
    # Or on Windows:
    copy target\release\git-commit-helper.exe C:\Windows\System32\
    

配置Claude桌面

你需要告诉Claude Desktop在哪里可以找到二进制文件。

📁 配置文件位置:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 窗户: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

编辑配置文件并添加:

{
  "mcpServers": {
    "git-commit-helper": {
      "command": "/absolute/path/to/git-commit-helper"
    }
  }
}

⚠️ 重要提示: 使用 绝对路径 到你的二进制!

平台特定示例:

macOS/Linux:

{
  "mcpServers": {
    "git-commit-helper": {
      "command": "/Users/yourname/git-commit-helper/target/release/git-commit-helper"
    }
  }
}

窗户:

{
  "mcpServers": {
    "git-commit-helper": {
      "command": "C:\\Users\\YourName\\git-commit-helper\\target\\release\\git-commit-helper.exe"
    }
  }
}

💡 提示: 要获取绝对路径,请执行以下操作:

# macOS/Linux:
cd git-commit-helper
echo "$(pwd)/target/release/git-commit-helper"

# Windows PowerShell:
cd git-commit-helper
echo "$pwd\target\release\git-commit-helper.exe"

重新启动克劳德桌面

完全退出并重新启动 Claude Desktop(不仅仅是关闭窗口-在macOS上使用Cmd+Q或在Windows/Linux上完全退出)。

📝 使用示例

用Claude尝试这些自然语言查询:

生成提交消息

  • “我已经进行了更改,请给我写一条提交消息”
  • “查看我的更改并建议常规提交消息”
  • “帮助我为这些更改编写提交消息”

审查变更

  • “告诉我我要承诺什么”
  • “我修改了哪些文件?”
  • “显示此存储库中的所有更改”

理解上下文

  • “显示最后10个提交”
  • “此项目中的提交消息样式是什么?”
  • “显示最近的提交,以便我匹配样式”

组合工作流

  • “看看我的阶段性更改和最近的提交,然后写一条符合我们风格的提交消息”
  • “告诉我我改变了什么,并帮助我决定先承诺什么”

🛠️ 可用工具

服务器提供了Claude可以使用的四个工具:

1. git_status

显示存储库的当前状态-已修改、暂存和未跟踪的文件。

参数:

  • repo_path (可选):git存储库的路径

例子: “显示我更改了哪些文件”

2. git_diff_staged

显示用暂存的文件的逐行更改 git add这就是将要承诺的。

参数:

  • repo_path (可选):git存储库的路径

例子: “告诉我我要承诺什么”

3. git_diff_all

显示存储库中的所有更改,包括已暂存和未暂存的更改。可以选择包含未跟踪的文件。

参数:

  • repo_path (可选):git存储库的路径
  • include_untracked (可选,默认值:false):包括未跟踪的文件

例子: “显示我的所有更改,包括未跟踪的文件”

4. git_log

显示最近的提交历史记录,以了解提交消息约定。

参数:

  • repo_path (可选):git存储库的路径
  • limit (可选,默认值:10,最大值:50):要显示的提交数

例子: “显示最后5次提交”

🔧 故障排除

macOS:“无法打开,因为无法验证开发人员”

macOS Gatekeeper可能会阻止二进制文件。要修复:

xattr -d com.apple.quarantine /path/to/git-commit-helper

Linux:“权限被拒绝”

使二进制文件可执行:

chmod +x /path/to/git-commit-helper

“不是git仓库”错误

确保您在已用初始化的目录中运行命令 git init 或者是一个克隆的存储库。

Claude Desktop找不到服务器

  1. 检查配置文件路径是否适合您的操作系统
  2. 验证您是否正在使用 绝对路径 二进制(不是相对的) ./git-commit-helper)
  3. 确保你 完全重新启动 Claude Desktop(不仅仅是关闭窗口)
  4. 检查Claude Desktop日志中的错误(通常与config位于同一文件夹中)

Windows:“无法识别git”

确保git已安装并位于PATH中:

# Test git installation
git --version

如果未安装,请从下载 git-scm.com

🏗️ 交叉编译

一次为所有平台构建:

./build.sh --all

这将为以下对象创建二进制文件:

  • Linux x86_64: target/x86_64-unknown-linux-gnu/release/git-commit-helper
  • macOS英特尔: target/x86_64-apple-darwin/release/git-commit-helper
  • macOS ARM: target/aarch64-apple-darwin/release/git-commit-helper
  • 窗户: target/x86_64-pc-windows-gnu/release/git-commit-helper.exe

手动交叉编译:

# Add target (one-time setup)
rustup target add x86_64-unknown-linux-gnu

# Build for that target
cargo build --release --target x86_64-unknown-linux-gnu

可用目标:

  • x86_64-unknown-linux-gnu -Linux x86_64
  • x86_64-apple-darwin -macOS英特尔
  • aarch64-apple-darwin -macOS苹果硅
  • x86_64-pc-windows-gnu -Windows x86_64

🤔 为什么是Rust?

单二进制分布
无需安装npm、pip或运行时。用户只需下载并运行。

即时启动
启动时间低于1ms,而Node.js/Python的启动时间为100-500ms。

小尺寸
基于Node.js的解决方案约为3MB,而30-50MB。

类型安全
编译时保证防止运行时错误。

官方SDK
采用Anthropic官方Rust MCP SDK构建,具有长期可靠性。

📖 文档

🤝 贡献

欢迎投稿!这是一个简单、专注的工具——请保持这种状态:

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 彻底测试
  5. 提交拉取请求

📄 许可证

MIT许可证-请参阅 许可证 文件以获取详细信息。

🙏 致谢

🔗 链接


由以下材料制成❤️ 使用Rust和官方的Anthropic MCP SDK