Git 工作流
commit / branch / PR 怎麼跟 Claude 協作,哪些不要讓它做。
TL;DR
- Claude 寫 commit message 比人快,因為它會看 diff 而不只看 staging area 的檔名
- PR 描述、issue triage 都可以丟給它,常用 prompt 包成 custom command(
/pr-desc) - 不該讓 Claude 自己做的事:
push --force、刪 branch、改別人的 commit、動 git config
一個情境:下午四點,要 commit 但腦子已經爛了
功能寫完了,diff 有 12 個檔。手動寫 commit message 通常變這樣:
fix stuff
reviewer 看到這個只能翻白眼。但要寫得好——「為什麼改 / 影響哪些檔 / 有沒有 breaking」——需要重新讀一輪 diff,這時候你已經懶了。
Claude 看 diff 寫 commit message 通常比下午累的時候手寫的好。它讀完整 diff,不是只看 git status 的檔名。
一個能用的 commit prompt
不要只說「幫我 commit」——Claude 會直接 git add -A && git commit && git push,這通常不是你要的。給它約束:
看 staged 的 diff(
git diff --staged),寫一個 conventional commit message。 格式:<type>(<scope>): <subject>+ 空行 + body 列出主要 change。 只 commit,不要 push。
這樣它會:
- 自己跑
git diff --staged讀變更 - 推斷 type(feat / fix / refactor / docs...)
- 寫一段比你手打詳細、又不囉唆的 message
- 停在 commit 完成這步——push 與否你自己決定
PR 描述包成 custom command
寫 PR 描述更累——要對比 base branch、整理多個 commit、想 reviewer 在意的點。這種重複工作直接包成 custom command。
在 .claude/commands/pr-desc.md 放:
跑 `git diff main...HEAD` 看這個 branch 跟 main 的差異,
寫 PR 描述。三段:
1. **Why**:為什麼要做(一句話)
2. **What changed**:條列主要修改
3. **Test plan**:怎麼驗證
不要含 emoji、不要含「Generated with Claude」字樣。
之後在 PR 前打 /pr-desc,Claude 自己讀 diff 給你貼得進 GitHub 的描述。Issue triage、changelog 整理都是同一招。
不該讓 Claude 自己做的事
不是「Claude 做不到」——是「就算它做得到,你也不該讓它自己決定」。分三類:
| 類別 | 例子 | 為什麼不該 |
|---|---|---|
| Destructive | push --force、reset --hard、刪 branch、clean -f | 改錯了找不回來 |
| Shared state | 改 main、改別人的 commit、rebase -i 別人的歷史 | 影響團隊,不是只有你 |
| Auth / config | 動 git config、改 credentials、改 remote URL | 賬號 / 簽章權限該由人控制 |
推薦的協作 pattern
- Claude 寫 message、人按下 push:commit / PR description 用 LLM 加速,但「公開動作」由人觸發
- 不 auto-stage:用
git diff --staged而不是git add -A,避免 Claude 把.env、node_modules當禮物送出去 - 任何 rewrite history 操作要人在線:
rebase、amend、reset在團隊 branch 上不該自動跑
接下來
上面那張表是用 prompt 寫的「君子協定」,Claude 可能違反。
要把「不該做的事」變成真的做不到,需要 Section 3 的主題:Hooks 是什麼——在 tool call 前插一個 script,destructive 指令直接 reject,比靠提示詞穩。

