Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitAI

A VS Code extension that adds a git icon to the top bar of the Source Control panel (next to Commit/Refresh). Click it to generate an AI commit message with the DeepSeek API and have it filled into the commit input box.

一个 VS Code 扩展:在源码管理面板标题栏(Commit/Refresh 旁边)添加 Git 图标按钮,点击即可调用 AI 大模型生成提交信息并自动填入提交输入框。


Features

  • Git icon button on the Source Control panel header bar (always visible, next to Commit/Refresh)
    源码管理面板标题栏常驻 Git 图标按钮(Commit/Refresh 旁边)

  • Reads the full working tree diff (git diff HEAD, staged + unstaged) plus branch name
    读取完整工作区 diff(git diff HEAD,暂存 + 未暂存)与分支名

  • Generates a Conventional Commits message (English, summary line <= 72 chars)
    按 Conventional Commits 规范生成提交信息(英文,摘要 ≤ 72 字符)

  • Auto-stages all changes before generating (gitai.autoStageAll, default on)
    生成前自动暂存全部变更(gitai.autoStageAll,默认开启)

  • Prefixes the summary with a type-matching emoji (gitai.addEmoji, default on)
    摘要开头自动添加类型匹配的 emoji(gitai.addEmoji,默认开启)

  • Model and API endpoint are configurable — works with any OpenAI-compatible LLM
    模型与接口地址可配置,兼容任意 OpenAI 兼容大模型

  • Writes the result into the git commit message input box for review
    结果自动填入提交输入框供审阅

  • Auto-detects the real git repository — works when the repo is a nested subfolder of the workspace (e.g. frontend-vue/, backend/) and with multiple open repos (uses the active editor's repo)
    自动定位真实 git 仓库根目录——仓库位于工作区的嵌套子目录(如 frontend-vue/backend/)或多个仓库并存时均可使用(优先当前活动编辑器所在仓库)

  • Errors are surfaced with clear messages (missing key, HTTP status, timeouts)
    错误提示完善(缺 Key、HTTP 状态、超时等)


Installation

  1. Install dependencies and package:
    安装依赖并打包:

    npm install
    npm run package

    Install the generated gitai-0.0.4.vsix via the Extensions view (Install from VSIX...).
    在扩展视图选择 Install from VSIX... 安装生成的 gitai-0.0.4.vsix

  2. For development, press F5 in VS Code to launch an Extension Development Host.
    开发调试时按 F5 启动扩展开发宿主。


Usage

  1. Make some changes in a git repository and open the Source Control panel.
    在 git 仓库中做出修改,打开源码管理面板。

  2. Click the git icon in the panel's top bar (next to the Commit/Refresh buttons).
    点击标题栏中的 Git 图标按钮(Commit/Refresh 旁边)。

  3. Review the generated message in the commit input box and commit.
    审阅填入提交输入框的生成结果,然后提交。


Configuration

How to configure the API 如何修改 API(API Key / 模型 / 接口地址)

  1. Open VS Code Settings (Ctrl + ,), or open settings.json via the Command Palette (Ctrl + Shift + PPreferences: Open User Settings (JSON)).
    打开 VS Code 设置(Ctrl + ,),或在命令面板(Ctrl + Shift + P)输入 Preferences: Open User Settings (JSON) 打开 settings.json

  2. Add or modify any of the following settings (gitai.* prefix):
    添加/修改以下任意配置项(gitai.* 前缀):

    {
      // 1. API Key(必填 / required)
      "gitai.apiKey": "sk-xxxxxxxxxxxxxxxxxxxx",
    
      // 2. 模型(可选,默认 deepseek-v4-flash,可换任意 OpenAI 兼容模型)
      "gitai.model": "deepseek-v4-flash",
    
      // 3. 接口地址(可选,默认官方地址;自建代理/中转站时修改)
      "gitai.baseUrl": "https://api.deepseek.com",
    
      // 4. 发送给模型的 diff 最大长度(默认 8,000 字符,约 2k token;
      //    超出部分自动截断,按需调大可获取更多上下文)
      "gitai.maxDiffLength": 8000,
    
      // 5. 生成前自动暂存全部变更(默认开启)
      "gitai.autoStageAll": true,
    
      // 6. 摘要前添加类型匹配 emoji(默认开启)
      "gitai.addEmoji": true
    }
  3. Changes take effect immediately, no restart needed. Get an API key at https://platform.deepseek.com/api_keys.
    保存后立即生效,无需重启。获取 API Key:https://platform.deepseek.com/api_keys

Settings reference 配置项一览

Setting Default Description
gitai.apiKey "" API key (required). Get a key at platform.deepseek.com/api_keys
gitai.model deepseek-v4-flash Model to use (any OpenAI-compatible model)
gitai.baseUrl https://api.deepseek.com API base URL, OpenAI-compatible mode
gitai.maxDiffLength 8000 Max diff characters sent to the API (roughly 1 token per 4 chars). Larger diffs are truncated; raise it if you need more context, lower it to save tokens
gitai.autoStageAll true Automatically run git add -A before generating
gitai.addEmoji true Prefix the summary with a type-matching emoji

You can also search gitai directly in the Settings UI to modify each setting individually (the gitai.apiKey input box supports pasting).
在设置界面中直接搜索 gitai 也可以逐个修改(gitai.apiKey 输入框支持粘贴 API Key)。


How GitAI works

Changelog 更新日志

v0.0.4

  • Fix: No changes to commit in multi-repo workspaces when the repo with changes is not the first discovered one (e.g. changes in backend/ while the active editor is in frontend/ or elsewhere). When several repositories exist under the workspace, GitAI now checks each one with git status --porcelain and picks the repository that actually has changes — if only one has changes it is used directly; if several do, the active editor's repository wins, otherwise you are asked to choose via a quick pick.
    修复多仓库工作区下"仓库有改动却提示 No changes to commit"的问题(例如 backend/ 有改动、而活动编辑器在 frontend/ 或别处)。当工作区下存在多个仓库时,GitAI 现在用 git status --porcelain 逐一检查,优先选择真正有改动的仓库——仅有 1 个有改动时直接使用;多个有改动时优先活动编辑器所在仓库,否则弹出快速选择框让用户指定。

v0.0.3

  • Fix: Failed to stage all changes: fatal: not a git repository when the workspace root is not itself a git repository (e.g. repos live in nested subfolders like frontend/, backend/, or monorepos). GitAI now resolves the actual repository root through the built-in git extension API — preferring the active editor's repository when several are open — and runs all git commands there, falling back to git rev-parse --show-toplevel when the API is unavailable.
    修复当工作区根目录本身不是 git 仓库时报 Failed to stage all changes: fatal: not a git repository 的问题(如仓库位于工作区嵌套子目录 frontend/backend/,或多仓库 monorepo 场景)。GitAI 现在通过内置 git 扩展 API 定位真实仓库根目录——多仓库时优先当前活动编辑器所在仓库——并在该目录执行所有 git 命令;API 不可用时回退到 git rev-parse --show-toplevel

v0.0.2

  • Fix: Failed to read git diff: stdout maxBuffer length exceeded — reads git output via streaming instead of a fixed buffer, no longer fails on very large diffs.
    修复大 diff 时 Failed to read git diff: stdout maxBuffer length exceeded 报错(改为流式读取 git 输出,不再受缓冲区大小限制)。
  • Change: default gitai.maxDiffLength lowered from 4,000,000 to 8,000 characters to avoid excessive token usage (roughly 2k tokens per request).
    默认 gitai.maxDiffLength 由 4,000,000 调整为 8,000 字符,避免单次请求消耗过多 token(约 2k token)。

v0.0.1

  • Initial release.
    首个版本。

License 许可

MIT

About

GitAI is a VS Code extension that adds a git icon to the Source Control panel header — one click stages your changes, sends the diff to any OpenAI-compatible model, and fills a Conventional Commits message (with matching emoji) into the commit input box.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages