# 在 AGENTS/CLAUDE MD 中强制 AI 修改文件后执行 git commit

- 来源：宝玉 (@dotey)
- 发布时间：2026-07-30 00:37
- AIHOT 分数：69
- AIHOT 链接：https://aihot.virxact.com/items/cms6bsysi01u9rotzuijjrccf
- 原文链接：https://x.com/dotey/status/2082505782440902700

## AI 摘要

在 AGENTS/CLAUDE MD 配置中加入指令：所有修改文件的实现任务必须在最终回复前完成一次 git commit。规则要求编辑前检查 `git status`，仅暂存当前任务相关文件或代码块，提交后报告 commit hash 且不推送、不修改历史。此举旨在解决 AI 修改代码后缺乏版本追踪、难以回溯的问题。

## 正文

在 AGENTS/CLAUDE MD 里面加一句：
Every implementation task that changes files MUST end with a git commit before the final response.

- Inspect `git status` before editing and treat pre-existing or concurrent changes as user-owned.
- Review the final diff and run proportionate verification before committing.
- Stage only files or hunks that belong to the current task. Never bundle unrelated changes unless the user explicitly asks.
- Use a concise descriptive commit message on `main`， report the commit hash， and do not push， amend， or rewrite history unless asked.
- Read-only tasks and tasks with no file changes do not create empty commits.

### 引用推文

> Xiangyu 香鱼🐬：我一定要教会我们团队的人怎么用git 现在ai改了一堆代码, 然后一个项目里完全没有提交过任何git状态 他妈的改天改到大动脉,自己都不知道改了啥
