(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=43468637

这篇 Hacker News 帖子讨论了提交信息的值和风格,起因是一篇文章提倡使用描述性的提交信息而不是严格格式化的提交信息。原作者认为像 "chore:" 这样的前缀不如用这些字符来添加细节更有用,尤其是在二分查找 bug 时。他们鼓励个人的写作风格和幽默感。 评论者们就理想的内容展开了辩论。一些人更喜欢简洁的、总结变更的提交信息,这可以通过分支合并(branch-and-squash)来实现。另一些人,例如 kqr 和 nloomans,批评了这些简短的总结,强调了解释变更 *原因* 的重要性,包括代码背后的需求和上下文。他们认为像“修复 X”或“添加 Y”这样的模糊信息在追踪 bug 时毫无帮助。一些人建议加入“原因”以防止未来的误解或破坏性更改。 其他观点包括 Gerrit 在审查提交信息方面的有用性,使用 Cursor 规则编写提交信息的可能性,以及对特定格式的偏好(简短描述,空行,详细信息)。一些人认为冗长的提交信息是浪费,而另一些人则认为它们对于调试和理解代码历史至关重要。讨论涉及到常规提交标准以及提交信息的用途,这些用途超出了变基(rebase)。

相关文章
  • 提交信息失落的艺术 2025-03-25
  • (评论) 2023-12-27
  • (评论) 2024-02-02
  • 我有点喜欢变基 2024-06-24
  • (评论) 2024-06-24

  • 原文
    Hacker News new | past | comments | ask | show | jobs | submit login
    The Lost Art of Commit Messages (seyhan.me)
    18 points by drac89 1 hour ago | hide | past | favorite | 18 comments










      Reject commit message suggestions
      
      When working on large software projects, commit messages that follow
      the format suggested by the author rarely provide additional value.
      Having commits prefixed by "chore:" or "docs(ui):" aren't that useful.
      Instead, some of those 50 characters can be used for more descriptive
      titles. Commit messages are often the best and only context available
      when bisecting a bug, so bullet points only really make sense when
      making a list. Prose works just fine.
      
      Writing styles vary across contributors but it's much more useful to
      get *anything* from someone in their preferred format than nothing at
      all because they are frustrated with rules. Some committers do have a
      special "committer voice" that they use when describing complex changes
      in a commit message. For example, the text here is slightly abridged
      and focuses less on the first person than what is typically expected.
      This evolves naturally from writing these.
      
      Finally, commit comments definitely should have jokes in them. This is
      actually more critical than wrapping them at 72 characters.


    This isn't prose, it's poetry.


    You get some of this for free if you create branches and squash merge them when finished. Without needing to think much about commit message, just a few words per commit is enough. This is good enough for me and I don't need to waste any time thinking about it.

    Example commits of something I worked on a few days back:

      $ git l feature/character-selection
    
      c54825f 3 days ago   Robert Schaap   (feature/character-selection) Simplify color picker, fetch current color
      d512569 3 days ago   Robert Schaap   Fix recolor for female, clean up files
      6d05ce4 3 days ago   Robert Schaap   Add color picker to change shirt color
      441180b 3 days ago   Robert Schaap   Show male in editor
      17045dc 3 days ago   Robert Schaap   Remove old character
      95772ff 3 days ago   Robert Schaap   Add characters
    
    Then when I squash merged it I ended up with this commit message:

      $ git show HEAD~1
    
      commit be50e0d701d565cebdf4f29e0c9d8030a1a8faf7
      Author: Robert Schaap
      Date:   Mon Mar 24 21:29:20 2025 +0100
    
        Character selection (#14)
    
        * Add characters
    
        * Remove old character
    
        * Show male in editor
    
        * Add color picker to change shirt color
    
        * Fix recolor for female, clean up files
    
        * Simplify color picker, fetch current color


    Granted, I'm not the target audience of your commit messages, but they tell me very little about what happens.

    > Add characters

    I can probably tell from the code that that's what's happening. But what requirements drove these particular characters?

    > Remove old character

    What makes it old? How would I recognise an old character in the future?

    > Show male in editor

    Why did male not show before? Was there a bug or a partially implemented feature?

    > Fix recolor for female, clean up files

    What does it mean to "fix recolor"? And even worse, what is "clean up files"? What requirements drove this file cleaning? Why were the files unclean in the first place?

    etc. Commit messages in the style of "fix X" or "add Y" or "remove Z" or "nondescript action on W" are the bane of my existence. They seem so meaningful but they don't tell me anything when I'm trying to trace why a particular bug was introduced – or whether it's even a bug in the first place.



    These example commits seem like pretty bad commit messages to me. They are just a summery of the changes (something a motivated reader can rediscover by reading the diff), while leaving out the why, which will be lost to history if not documented.


    Depends. Sometimes a one-liner or a reference to a ticket is enough.

    There are times when I make a one-line change and write a paragraph or two explaining why it had to be done. But these kinds of things often drown in the noise of a dozen other changes. If that one was important enough, I will reference it in an ongoing discussion or documentation, or at least include "read below:" on the first line.

    I usually see people include a more elaborate commentary with the pull request. If the changeset is good but the series of individual commits is a bit messy, just merge by squashing.

    (Also: this comment is meta.)



    I prefer:

    Using a type is to contrived, because your commit will often include e.g documentation and a feature. Splitting them for the sake of following this pattern makes no sense.



    Do people really gain as much time from being able to read these long messages as they lose in writing them?

    I don't think my team would.

    Did the author measure this ? If not, he's the monkey.



    I rarely read the commit messages. It's often faster to just read the code than an obscure description, I'd rather have a small sentence that summarizes what the diff is doing than a technical paper explaining every change in the commit. I don't read pass the title.


    Most of the time that's fine, but then you'll find a bit of code that's broken and the change that added it makes no sense and the commit message is empty. Kind of infuriating.


    And please include the why.

    From the article: "- adjust timeout settings to prevent crashes". Include the details of why the timeout setting lead to crashes; what were the inputs and the cases that caused this.

    This lets us decide whether the fix stays or goes the next time there is an issue in the same piece of code, or your commit broke something unrelated - the person fixing it needs to know _why_ you changed the code.



    One of the best things about Gerrit - besides stacking and turn-by-turn review - is how it emphasizes good commit messages by making them part of the process.

    Each commit becomes one "unit of review", and the commit message can be reviewed just like the code changes.



    Wow, thanks for this page, I can almost take it as-is and create a Cursor rule for writing commit messages ^^’


    nit: the author proposes "short descriptions" like "fix null pointer exception in payment module" and "refactor data processing pipeline", however "fix" and "refactor" are already in the "type" part of the commit message. Possibly, "payment module" and "data processing pipeline" can (should?) be extracted from the "scope" element. The characters left over after the type and scope can be used smarter.


    Similar to https://www.conventionalcommits.org/en/v1.0.0/ right?

    I wouldn't say its a lost art... we do this at our company



    --message "wip"

    Why do we care about commit messages? I only read them when rebasing.



    They are incredibly helpful when you are trying to find where a bug was introduced, and trying to figure out why some piece of code is the way it is.


    >while pushing changes that could rival a novel in length

    How is distilling a novel down to a short description and 2 points any better? This format is too limiting.







    Join us for AI Startup School this June 16-17 in San Francisco!


    Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



    Search:
    联系我们 contact @ memedata.com