展示HN:培养编写有意义的提交信息的习惯
Show HN: Build the habit of writing meaningful commit messages

原始链接: https://github.com/arpxspace/smartcommit

## Smartcommit:轻松生成规范提交信息 **smartcommit** 是一款由人工智能驱动的 CLI 工具,旨在简化语义化、符合 Conventional Commits 规范的提交信息的创建。它会分析你暂存的代码变更,并智能地询问你做出这些变更的*原因*,从而超越代码本身所能揭示的信息。 smartcommit 使用 OpenAI (GPT-4o) 或本地 Ollama (Llama 3.1) 模型,生成结构良好、严格遵循 Conventional Commits 规范的提交信息 (feat, fix, chore 等)。 安装简单,使用 `go install` 即可。使用方法是将 `git commit` 替换为 `git ci` (配置别名后)。该工具具有用户友好的终端用户界面 (TUI),引导你完成分析、提问、审查和最终提交。配置存储在本地,并且可以自动检测 OpenAI API 密钥。 smartcommit 旨在提高代码历史的清晰度和可维护性,为未来的你(和你的团队)节省宝贵的时间和精力。欢迎贡献!

## SmartCommit:AI 辅助提交信息 - 摘要 一位开发者创建了“SmartCommit”(github.com/arpxspace),旨在帮助编写更有意义的提交信息,起因是对几个月后忘记代码更改背后的原因感到沮丧。该工具会向用户询问有关其更改的问题,旨在将“是什么、如何做以及为什么”转化为合适的提交信息,而不是依赖 AI 独立生成。 Hacker News 的讨论引发了争论。一些人赞扬了这个想法,强调详细的提交历史对于未来的理解和协作的价值,尤其是在入职新团队成员或调试旧代码时。另一些人认为提交信息应该简洁,或者将精力更好地花在编码本身上。人们担心 AI 生成的信息可能冗长且缺乏关键上下文,从而可能用无用信息污染历史记录。 许多人强调了*人类*思考在编写提交信息中的重要性,建议该工具可以作为批判/改进辅助工具,而不是生成器。讨论还涉及最佳实践,例如原子提交、链接到问题跟踪器,以及像 Conventional Commits 这样的规范的实用性——尽管对后者的看法不一。最终,该讨论强调了在文档工作量与开发速度之间取得平衡的持续挑战。
相关文章

原文

smartcommit is an intelligent, AI-powered CLI tool that helps you write semantic, Conventional Commits messages effortlessly. It analyzes your staged changes, asks clarifying questions to understand the "why" behind your code, and generates a structured commit message for you.

Future you will thank you for deciding to use smartcommit!

smartcommit Demo

  • AI-Powered Analysis: Automatically analyzes your staged git diff to understand what changed.
  • Interactive Q&A: Asks you specific, relevant questions to gather context that isn't obvious from the code alone (the "why" and "intent").
  • Multi-Provider Support:
    • OpenAI (GPT-4o): For top-tier accuracy and performance.
    • Ollama (Llama 3.1): Run locally and privately for free.
  • Conventional Commits: strictly enforces the Conventional Commits specification (feat, fix, chore, etc.).
  • Beautiful TUI: A responsive, easy-to-use Terminal User Interface built with Bubble Tea.
  • Go (1.21 or later)
  • Git installed and available in your PATH.
  • (Optional) Ollama installed locally if you plan to use the local model.
go install https://github.com/arpxspace/smartcommit@latest
  1. Clone the repository:

    git clone https://github.com/arpxspace/smartcommit.git
    cd smartcommit
  2. Build the binary:

  3. Move to your PATH (optional):

    mv smartcommit /usr/local/bin/

Use instead of git commit

To use smartcommit as your default git commit command, run:

git config --global alias.ci '!smartcommit'

Or for this repository only:

git config alias.ci '!smartcommit'

Usage:

  • To commit with smartcommit: git ci
  1. Stage your changes:

  2. Run smartcommit:

  3. Follow the TUI:

    • First Run: You'll be asked to choose your AI provider (OpenAI or Ollama) and configure it.
    • Analysis: The AI will analyze your changes.
    • Questions: Answer a few questions to provide context.
    • Review: The AI generates a commit message. You can edit it or confirm it to commit immediately.

If you already know what you want to write, you can select "I already know what to write" from the main menu to open your default git editor.

smartcommit stores its configuration in a local file (usually ~/.smartcommit/config.json).

  • OPENAI_API_KEY: If set, smartcommit can detect this during setup and ask if you want to use it, saving you from pasting it manually.

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Distributed under the MIT License. See LICENSE for more information.

联系我们 contact @ memedata.com