JSPM

@baihuishou/git-ai-commit

1.0.7
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q59989F
  • License MIT

使用大模型自动生成Git提交信息

Package Exports

  • @baihuishou/git-ai-commit
  • @baihuishou/git-ai-commit/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@baihuishou/git-ai-commit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

git-ai-commit

使用大模型自动生成Git提交信息。

功能

  • git ac - 自动生成提交信息并提供多个候选选项
  • git aac - 执行 git add . 然后生成提交信息
  • git acp - 生成提交信息,然后 git push
  • git aacp - 执行 git add .,生成提交信息,然后 git push

安装

方法一:从npm安装

npm install -g @baihuishou/git-ai-commit

安装后,包会自动配置Git别名。如果自动配置失败,你可以手动设置以下别名:

git config --global alias.ac "!git-ac"
git config --global alias.aac "!git-aac"
git config --global alias.aacp "!git-aacp"
git config --global alias.acp "!git-acp"

方法二:从GitHub安装

# 直接从GitHub安装
npm install -g github:baihuishou/git-ai-commit

# 或者克隆后本地安装
git clone https://github.com/baihuishou/git-ai-commit.git
cd git-ai-commit
npm install
npm install -g .

方法三:离线安装

# 下载git-ai-commit-1.0.0.tgz文件后
npm install -g /path/to/git-ai-commit-1.0.0.tgz

配置

首次运行时会自动创建配置文件。你可以使用以下命令配置API密钥:

# 使用交互式配置助手
git ac --config

配置文件位于 ~/.git-ai-commit/config.json,可配置多个大模型:

{
  "defaultModel": "deepseek",
  "models": {
    "deepseek": {
      "url": "https://api.deepseek.com/v1",
      "apiKey": "your-api-key",
      "model": "deepseek-coder"
    },
    "gemini": {
      "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro",
      "apiKey": "your-api-key",
      "model": "",
      "streamGenerateContent": true
    },
    "openai": {
      "url": "https://api.openai.com/v1",
      "apiKey": "your-api-key",
      "model": "gpt-4"
    }
  },
  "customModels": []
}

特别说明:Gemini配置

对于Gemini模型,配置方式有两种:

方式一:在URL中包含完整模型路径(推荐)

{
  "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro",
  "apiKey": "your-api-key",
  "model": "",
  "streamGenerateContent": true
}

方式二:URL和模型分开配置

{
  "url": "https://generativelanguage.googleapis.com/v1beta/models",
  "apiKey": "your-api-key",
  "model": "gemini-1.5-flash",
  "streamGenerateContent": true
}

例如,可以使用类似以下的curl命令调用Gemini:

curl --location --request POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse&key=your-api-key' \
--header 'Content-Type: application/json' \
--data-raw '{
  "contents": [
    {
      "parts": [
        {
          "text": "提示内容"
        }
      ]
    }
  ]
}'

本地模式

如果没有配置API密钥,工具会自动使用本地模式,基于代码变更生成简单的提交信息。这种模式不需要联网,但生成的提交信息质量可能不如使用大模型的结果。

添加自定义模型

git ac --add-model "modelName" --url "https://your-model-api.com" --api-key "your-api-key" --model-name "your-model-name"

设置默认模型

git ac --set-default "modelName"

使用示例

# 自动生成提交信息
git ac

# 先添加所有更改然后提交
git aac

# 提交并推送
git acp

# 添加所有更改,提交并推送
git aacp

常见问题

Git别名未生效

如果安装后Git别名未生效,可以尝试以下方法:

  1. 检查Git别名是否已设置:

    git config --global --list | grep alias
  2. 手动设置别名:

    git config --global alias.ac "!git-ac"
    git config --global alias.aac "!git-aac"
    git config --global alias.aacp "!git-aacp"
    git config --global alias.acp "!git-acp"
  3. 确保npm全局安装目录在PATH中:

    # 查看npm全局安装路径
    npm config get prefix
    
    # 确保该路径在你的环境变量PATH中

命令未找到

如果遇到"command not found"错误,可能是因为npm全局安装目录不在PATH中。解决方法:

  1. 查看npm全局安装路径:

    npm config get prefix
  2. 将路径添加到环境变量PATH中:

    • Windows: 在系统环境变量中添加
    • macOS/Linux: 在/.bashrc或/.zshrc中添加
      export PATH="$(npm config get prefix)/bin:$PATH"