Skip to content

Mikimoto/git-auto-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git AI Tools

AI 輔助的 Git 子命令工具集,幫助你自動生成 commit messages 和 release notes。

功能

  • git-auto-commit - 分析 staged changes,使用 AI 生成 commit message
  • git-release-note - 比較分支差異,使用 AI 生成 release note

支援的 AI 服務

服務 環境變數 預設模型
Google Gemini GEMINI_API_KEY gemini-flash-latest
Anthropic Claude ANTHROPIC_API_KEY claude-3-haiku
OpenAI GPT OPENAI_API_KEY gpt-3.5-turbo

優先順序:Gemini > Claude > OpenAI(可透過 PREFERRED_AI_PROVIDER 調整)

安裝

# 1. Clone 或下載此專案
git clone https://github.com/your-repo/git-auto-commit.git

# 2. 設定執行權限
chmod +x git-auto-commit git-release-note

# 3. 建立 symlink 到 PATH(擇一)
ln -s $(pwd)/git-auto-commit /usr/local/bin/git-auto-commit
ln -s $(pwd)/git-release-note /usr/local/bin/git-release-note

# 或直接複製到 PATH
cp git-auto-commit git-release-note /usr/local/bin/

相依套件

# macOS
brew install jq fzf

# Ubuntu/Debian
sudo apt-get install jq fzf
  • jq - JSON 處理(兩個工具都需要)
  • fzf - 互動式選單(僅 git-auto-commit 需要)

環境變數設定

# 設定 API Key(至少需要一個)
export GEMINI_API_KEY="your-gemini-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export OPENAI_API_KEY="your-openai-api-key"

# 可選:指定 Gemini 模型
export GEMINI_MODEL="gemini-2.5-pro"

# 可選:指定優先使用的 AI 服務
export PREFERRED_AI_PROVIDER="gemini"  # gemini, claude, openai

git-auto-commit

分析 staged changes 並使用 AI 生成多個 commit message 選項,透過 fzf 互動選擇。

使用方式

# 先 stage 你的變更
git add .

# 執行 auto-commit
git auto-commit

功能特色

  • 分析 staged 的程式碼變更
  • AI 生成 5 個符合 Conventional Commits 格式的選項
  • 使用 fzf 互動式選擇,並可預覽 diff
  • 支援自訂 commit message
  • 自動 fallback 到其他 AI 服務

範例輸出

🤖 Git Auto-Commit with AI

📊 AI 服務狀態:
  ✓ Google Gemini (已設定, 模型: gemini-flash-latest)
  ○ Anthropic Claude (未設定)
  ○ OpenAI GPT (未設定)

📝 Staged changes:
 src/utils.ts | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

🔍 分析變更內容...
💭 使用 AI 生成 commit messages...

📋 請選擇一個 commit message:
> feat(utils): add input validation helper function
  fix(utils): resolve edge case in string parser
  refactor(utils): improve error handling logic
  [自訂] 輸入自己的 commit message
  [取消] 不要 commit

git-release-note

比較當前分支與主分支(main/master)之間的所有 commits,使用 AI 生成專業的 release note。

使用方式

# 基本使用(自動偵測 main 或 master)
git release-note

# 指定基準分支
git release-note -b develop

# 輸出到檔案
git release-note -o CHANGELOG.md

# 複製到剪貼簿
git release-note --copy

# 指定輸出格式
git release-note -f markdown  # 預設
git release-note -f plain     # 純文字
git release-note -f json      # JSON 格式

# 組合使用
git release-note -b develop -o release-notes.md --copy

參數說明

參數 說明
-b, --base <branch> 指定比較的基準分支(預設自動偵測 main/master)
-o, --output <file> 輸出到指定檔案
-f, --format <format> 輸出格式:markdown, plain, json
--copy 複製到剪貼簿
-h, --help 顯示說明

功能特色

  • 自動偵測主分支(main 或 master)
  • 收集所有 commits 和檔案變更
  • AI 分類整理:Features、Bug Fixes、Improvements、Breaking Changes
  • 輸出繁體中文 release note
  • 支援多種輸出格式

範例輸出

📝 Git Release Note Generator

📊 AI 服務狀態:
  ✓ Google Gemini (已設定, 模型: gemini-flash-latest)

📌 當前分支: feature/new-feature
📌 基準分支: main

📊 發現 8 個 commits

📋 Commits 列表:
  a1b2c3d - feat: add user authentication
  e4f5g6h - fix: resolve login timeout issue
  ...

════════════════════════════════════════
📄 Release Note
════════════════════════════════════════

## Release Notes

### 新功能
- 新增使用者認證系統
- 支援 OAuth 2.0 登入

### 問題修復
- 修正登入逾時問題
- 解決 session 過期未正確處理的問題

### 改進
- 優化登入流程效能

Debug 模式

如需查看詳細的 API 請求和回應資訊:

DEBUG=1 git auto-commit
DEBUG=1 git release-note

License

MIT License

About

Git custom command for use AI to check stage file and generate commit message

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages