A VS Code extension that suggests meaningful Git commit messages based on your staged changes using AI-powered generation via the Hugging Face Inference API.
Features
Git Integration: Analyzes staged changes with git diff --staged.
AI-Powered Suggestions: Generates commit messages using a free Hugging Face model (e.g., Mixtral-8x7B-Instruct).
User Interface: Displays suggestions in a VS Code Quick Pick modal, allowing you to approve, edit, or regenerate messages.
Commit Execution: Commits directly with git commit -m when a message is approved.
Customization: Supports different commit styles (Conventional Commits, casual, detailed) and API token configuration.
Error Handling: Provides feedback for Git or API issues.
Installation
Install from VS Code Marketplace (once published):
Search for Git Commit AI in the Extensions view (Ctrl+Shift+X or Cmd+Shift+X).
Click Install.
Manual Installation (for development):
Clone this repository:
git clone https://github.com/yourusername/git-commit-ai.git
cd git-commit-ai
Install dependencies:
npm install
Open in VS Code and press F5 to run in Extension Development Host mode.
Prerequisites
Git: Installed and available in your PATH (run git --version to check).
Hugging Face API Token: A free token from huggingface.co with Read access.
Usage
Stage Changes:
Make changes in your Git repository and stage them:
git add .
Generate Commit Message:
Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
Run Suggest Commit Message.
A Quick Pick menu will appear with:
A suggested commit message.
Options to "Regenerate" or "Custom" (write your own).
Approve or Edit:
Select the suggestion and press Enter to commit.
Choose "Custom" to edit the message in an input box.
Select "Regenerate" to get a new suggestion.
Commit:
The extension executes git commit -m "<message>" and shows a success message.
Configuration
Customize the extension via VS Code settings:
gitCommitAI.apiToken:
Your Hugging Face API token.
Default: "" (empty, must be set).
How to set: Open Settings (Ctrl+,), search for gitCommitAI.apiToken, and paste your token.
gitCommitAI.commitStyle:
Style of generated commit messages.
Options: conventional, casual, detailed.
Default: conventional.
Examples:
conventional: feat: add new feature
casual: Yo, added some cool stuff!
detailed: Updated the button text from "CV" to "Download CV" for clarity
Example
Stage a change:
echo "Download CV" > page.tsx
git add page.tsx
Run Suggest Commit Message.
See a suggestion like:
Casual: Changed the CV button text, yo!
Press Enter to commit.
Troubleshooting
"No staged changes found":
Ensure you’ve staged changes with git add.
Verify you’re in a Git repository folder (run git status).
"AI API error: 401 Unauthorized":
Check your Hugging Face API token in settings.
"AI API error: 429 Too Many Requests":
You’ve hit the free tier rate limit. Wait or upgrade to a Hugging Face PRO account.