Show HN:自动创建组织化PR提交的工具
Show HN: Tool to Automatically Create Organized Commits for PRs

原始链接: https://github.com/edverma/git-smart-squash

厌倦了混乱的提交历史?Git Smart Squash 使用 AI 自动将您的 Git 提交重新组织成逻辑清晰、结构良好的更改,只需几秒钟。您将获得干净、描述性的提交,符合常规提交标准,而不是一堆“修复错别字”和“进行中”的提交。 安装非常简单:`pip install git-smart-squash`。您可以选择使用 Ollama(默认)的本地、免费和私有 AI,或使用基于云的选项,如 OpenAI、Anthropic 或 Gemini(需要 API 密钥)。运行 `git-smart-squash` 可查看拟议更改的计划后再应用,或使用 `--auto-apply` 跳过确认。 Smart Squash 会创建一个备份分支以便轻松恢复,并且永远不会自动推送,确保您始终掌控全局。您可以使用项目特定或全局配置文件来自定义行为。如果您遇到“无更改”或“差异过大”错误,请确保您在已提交工作的特性分支上,或尝试分解大型更改。

Edverma2 推出了一个工具,利用 AI(理想情况下是用于保护隐私的本地 Ollama 服务器)来自动组织和创建用于拉取请求的提交。该工具分析特性分支与其基分支之间的差异,然后使用大型语言模型 (LLM) 来建议一系列更小、描述更完善的提交。用户可以接受这些建议,重写其提交历史以匹配,然后强制推送到远程仓库。同时,系统会始终创建一个备份分支,以便轻松回滚。 然而,iandanforth 建议不要这样做,他主张每个工单只使用一个压缩提交。此提交应使用工单标题作为消息和描述,使代码更改与计划好的、范围明确的工作单元保持一致。这种方法可以保持主分支提交历史的整洁,并直接与工单管理系统相关联。
相关文章

原文

Use AI to transform your messy commit history into clean, logical commits that reviewers will love

Why Use Git Smart Squash?

Ever spent 30 minutes reorganizing commits before a PR? We've all been there. Git Smart Squash uses AI to automatically organize your changes into logical, well-structured commits in seconds.

Before (your typical feature branch):

* 7f8d9e0 fix tests
* 6c5b4a3 typo
* 5a4b3c2 more auth changes
* 4d3c2b1 WIP: working on auth
* 3c2b1a0 update tests
* 2b1a0f9 initial auth implementation

After (AI-organized commits):

* a1b2c3d feat: implement complete authentication system with JWT tokens
* e4f5g6h test: add comprehensive test coverage for auth endpoints

The AI analyzes your entire diff and groups related changes together, creating clean commit messages that follow conventional commit standards.

pip install git-smart-squash

2. Set up AI (choose one)

Option A: Local AI (Free & Private) - Default for Privacy

# Install Ollama from https://ollama.com
ollama serve
ollama pull devstral

Option B: Cloud AI (if you have API keys)

export OPENAI_API_KEY="your-key"      # or
export ANTHROPIC_API_KEY="your-key"   # or
export GEMINI_API_KEY="your-key"
cd your-git-repo
git checkout your-feature-branch

# Run it - shows the plan and asks for confirmation
git-smart-squash

# Or auto-apply without confirmation prompt
git-smart-squash --auto-apply

That's it! Your commits are now beautifully organized.

"I need to clean up before PR review"

git-smart-squash              # Shows plan and prompts for confirmation
git-smart-squash --auto-apply # Auto-applies without prompting

"I work with a different main branch"

git-smart-squash --base develop

"I want to use a specific AI provider"

git-smart-squash --ai-provider openai

"I use the short command"

gss  # Same as git-smart-squash

Don't worry - Git Smart Squash is designed to be safe:

  • Dry run by default - always shows you the plan first
  • Always creates a backup branch before making changes
  • Never pushes automatically - you stay in control
  • Easy recovery - your original commits are always saved
# Your original branch is always backed up
git branch | grep backup  # Find your backup
git reset --hard your-branch-backup-[timestamp]
Provider Cost Privacy Setup
Ollama (default) Free 100% Local ollama pull devstral
OpenAI ~$0.01/use Cloud Set OPENAI_API_KEY
Anthropic ~$0.01/use Cloud Set ANTHROPIC_API_KEY
Gemini ~$0.01/use Cloud Set GEMINI_API_KEY

Advanced Configuration (Optional)

Want to customize? Create a config file:

Project-specific (.git-smart-squash.yml in your repo):

ai:
  provider: openai  # Use OpenAI for this project

Global default (~/.git-smart-squash.yml):

ai:
  provider: local   # Always use local AI by default

Install Ollama from https://ollama.com and run:

ollama serve
ollama pull devstral

"No changes to reorganize"

Make sure you're on your feature branch with committed work:

git diff main  # Should show differences from main

"Large diff taking too long" or "Token limit exceeded"

When using Ollama (local AI), there's a hard limit of 32,000 tokens (roughly 128,000 characters). For large diffs, try:

  • Breaking your work into smaller chunks
  • Using --base with a more recent commit
  • Switching to a cloud provider for this operation: --ai-provider openai

Check out our detailed documentation or open an issue!

MIT License - see LICENSE file for details.


Made with love for developers who want cleaner git history

联系我们 contact @ memedata.com