Proper Commit Messages

我与影子孤独终老i 提交于 2019-12-21 04:41:16

问题


What are commit messages for? I've always been writing them as an explanation of what I did, but I've recently gotten into a discussion about it with a colleague who writes commit messages explaining why he did. Which one is right, or is there another answer entirely?

NOTE: I have absolutely no idea if there is a "right" answer for this. As such, I've labeled it community wiki and will not accept an answer. Upvotes shall decide the winner :)


回答1:


As a personal preference, I can tell what was done by looking at the differences in the files directly. The why is the thing I can't infer from just looking at the actual changes.

If the changes are significant or complicated, then I would include not only the why, but also a brief overview of the how.




回答2:


I think both are useful. A quick description of what changed ("Adding length validation for AddUserForm") is easier than looking at a diff, especially if you're browsing multiple commits. Why the change was made, what bug it fixed, etc. is obviously a very good thing to have, too.




回答3:


Commit messages are what you make of them, but when there are hundreds of them for a particular file, or thousands for a project, you want to be able to scan through them looking for certain changes or the nature of the changes. In effect, they are like code comments, and they need to be as helpful as possible, yet concise and pithy. Maybe best to think of them as tweets - convey maximum meaning in a short space.

As somebody who's worked on large code bases spanning decades, and also smaller projects spanning a year or two, I've found nothing more infuriating when combing commit logs than messages like "oops" or "fixed bug". If you fixed a bug, tell us which one (a bug number, at the very least). It's all important for the inevitable forensics down the road.




回答4:


I use the commit message as an executive summary of what was changed.

Executive summary is a [...] short document that summarizes [...] in such a way that readers can rapidly become acquainted with a large body of material without having to read it all.

The why is documented somewhere else: an issue tracking system, requirements documentation, etc. I also include links from the commit message to the why, and vice versa.



来源:https://stackoverflow.com/questions/3011471/proper-commit-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!