将提交说明作为思考工具
Commit description as a thinking tool

原始链接: https://yedhu.me/posts/commit-description-as-a-thinking-tool/

在使用 AI 编写代码之前,我会为重大改动撰写详细的提交说明,解释改了什么,更重要的是说明为什么改。这需要重新阅读并评估代码,常常还会带来改进,同时把关键的推理保留给后来的读者。 AI 生成的提交说明带来了一种新的风险:智能体可能不了解对话、项目工具或未记录决策中的上下文,于是编造看似合理的理由。给智能体提供更多上下文可以降低这一问题,但无法验证代码是否真的实现了提交说明所声称的内容。 因此,自己撰写提交信息仍然很有价值。它会迫使我审查改动、确认其目的,并识别出那些可能只存在于我脑海中的临时决策和退出条件。如果我无法解释为什么要做某项改动,那我可能并没有真正理解它,或者还没准备好交付它。即使代码由智能体编写,亲自写下变更原因仍然是一种必要的思考和验证方式。

《The Hacker News》上的一则讨论将提交说明视为一种思考工具,而非事务性工作。撰写提交信息,尤其是解释“为什么要这样改”,可以暴露知识盲点、揭示隐含假设、厘清替代方案,并避免糟糕决策演变成技术债。有些开发者会在编码前先写提交信息、PR 描述、ADR 或 AI 提示词,以便更好地理解并掌控自己的改动。 AI 可以通过质疑假设、研究背景、提供信息来源或起草待修改的文本来提供帮助。然而,将整个过程完全交由 AI,可能产出空泛或冗长的描述、虚构的改动动机,以及脆弱的实现。提交信息应记录无法从代码中推断出的业务背景或历史背景;具体做了什么,通常可以从 diff 中看出。 参与者对于“写作本身是否就意味着思考”存在分歧。有些人认为,即使是不完美的写作也能改善推理;另一些人则表示,重复且不经思考的写作只是机械劳动。总体而言,讨论更倾向于由人主导,并对改动原因作出简洁说明。
相关文章

原文

Before the AI era, I wrote pretty long commit descriptions (or commit bodies) for major changes. It took me about five to ten minutes to draft and reread them to make sure I didn’t miss anything important. I did that for several reasons.

I wanted to include all the useful information so readers wouldn’t have to hunt for it in multiple places.

I wanted to explain what and, more importantly, why. The “what” summarizes the changes that are generally self-explanatory, but it gives a starting point for explaining the “why.”

Sometimes, I write it in first person, like I am drafting a message for someone: “I did this because…”, “I am doing this until we…” etc. I then go ahead and explain why, so that it is easier for others, and most importantly for my future self, to understand why we made that change.

It was a good exercise. It wasn’t just about writing the commit message and description. The writing process itself helps me reflect on the code I wrote. I reread the code and summarize the changes. During that process, I tend to re-evaluate the decisions, and sometimes that leads to a different or better change.

Now we are in the era of agentic coding, where everything from code to commit descriptions is written by AI. There is a huge debate on whether we should read the AI-written code, and how difficult that is in terms of readability. The part I find difficult is reading and understanding AI-written commit descriptions.

Agents can write commit messages for the changes they make. But they may not have the full context that is spread across different communication and project management tools. Some of those might be offline too. When the AI doesn’t know the ‘why’ part, it comes up with its own reasoning. I find that dangerous. When we read that later, it may not make sense, because the real reason was completely different.

One obvious solution is to give the agent all the context it needs, through chat or tools. This helps to fix the issues with fabricated reasoning. The agent can now explain the “why” clearly.

But this doesn’t fix the other problem. The agent with the right context will write a convincing commit message. But only I can verify if the code does what the description says. So, here is something I do:

Write the commit message and description myself.

Here is why.

Writing a commit description myself helps me to reflect on the changes AI made. It is also a way to check if everything is as intended. If I cannot explain “why,” I am shipping something I don’t understand, which will be hard to explain or fix if it breaks later. It goes back to the old quote. If you cannot explain it, you did not understand it. The commit description again works here as a thinking tool.

Some parts, like “I am doing this until we…”, are temporary decisions with exit criteria. We sometimes set exit conditions, and AI cannot infer them from code or other tools because they are usually not written down anywhere since they seem too obvious to mention. But writing the commit message forces me to complete that sentence, and it helps future readers decide whether to keep that change.

The agent can write the code and the description. But writing why is where you find out whether you understand what you are shipping.

联系我们 contact @ memedata.com