提交消息有什么用?
我很难问这个问题,但就是这样。 几年来我一直在使用不同系统(svn、hg、git)的多个项目使用源代码控制,并且我学会了如何通过遵循指南等来改进我的消息。 但据我记忆,事后我再也没有看过它们。
那么...您如何从自己的提交消息中获利?当我因为破坏了某些东西并需要重新开始而需要返回时,我通常只是返回到最新的“节点”(我开始或合并分支的地方)。我是否只为那些好奇正在发生什么事情的监控项目的人编写这些消息?
问候
I struggled asking that question but here it is.
I am using source control since several years for multiple projects using different systems (svn, hg, git) and I learned how to improve my messages by following guidelines etc.
But as far as I can remember I never ever had a look at them afterwards.
So ... how do you profit from your own commit messages? When I need to go back because I smashed something and need a fresh start, I usually just go back to the latest "node" (where I started or merged a branch). Do I write those messages just for people monitoring the project who are curious what is going on?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你写它们是为了对未来的自己和团队中的其他人有所帮助。给你一些我发现它们有用的背景:
我曾经参与过一个项目,其中提交消息非常宝贵——我不止一次使用它们来追踪多年以前的代码。在该项目中,我们的错误跟踪系统还与我们的 VCS (ClearCase) 集成。因此,当您签入更改时,它会在提交注释中记录错误编号。这对于让您准确追溯更改的内容和原因非常有帮助。
总而言之,尽管如果您刚刚开始(特别是如果您是唯一参与该项目的人),提交消息可能看起来毫无意义,但一旦您拥有了一个由多个开发人员在生产中支持的成功产品,它们就变得非常宝贵。
更新
提交消息的另一个有用的功能是它们要求您检查并总结您刚刚所做的更改。即使我记得我更改了什么,我通常会在签入之前对文件进行快速比较。我会再次简短地阅读它,以确保没有拼写错误,我更改了我想要更改的所有内容,等等。这是一种检查代码是否存在小错误的简单方法,否则这些小错误可能会进入您的代码。无论如何,完成此操作后,我对更改的内容有了清晰的了解,因此我在签入文件时用它来编写更改的简明摘要。这是一个简单的习惯,只需您付出很少的努力就可以帮助提高代码质量。
You write them as an aid to your future self, and others on the team. To give you some background of when I have found them useful:
I used to work on a project where commit messages were invaluable - on more than one occasion I used them to track down code that was years old. On that project our bug tracking system was also integrated with our VCS (ClearCase). So when you checked in a change, it would record the bug number in the commit comments. This was very helpful to allow you to trace back exactly what was changed and why.
So to sum it up, although commit messages may seem pointless if you are just starting out (especially if you are the only one working on the project), they become invaluable once you have a successful product that is supported in production by multiple developers.
Update
Another useful feature of commit messages is that they require you to review and summarize the changes you just made. Even if I remember what I have changed, I will often do a quick diff of a file before checking it in. I will briefly read it all over again to make sure there are no typo's, that I changed everything I meant to, etc. This is a simple way to review your code for those small little bugs that would otherwise find their way into your code. Anyway, after doing this I have a clear picture of what changed, so I use this to write a concise summary of the change when checking in the file. This is a simple habit that helps increase code quality with little effort on your part.
“给我发一份你过去两周所做的事情清单”——老板
"Send me a list of the things you did in the past two weeks" - Boss
您的消息更多是针对其他用户而不是您自己。尽管我也确保在个人存储库上放置良好的提交消息。当您在某个项目上分心并在几个月后访问该项目以了解项目最近完成的工作时,这会有所帮助。
Your messages are more for other users than yourself. Although I make sure to place good commit messages even on personal repos as well. Helps when you get sidetracked on a project and visit it months down the line to get a handle of the recent work done on a project.
我发现的一件事是,提交消息是防止自己提交不够频繁的好方法。如果我无法将更改放入简短的提交消息中,我可能应该早点提交更改。
One thing I've found is that the commit messages are a good way to keep myself from not committing often enough. If I can't put the changes into a short commit message I probably should have committed the changes earlier.
在最好的情况下,提交绑定到功能/错误跟踪器中的工作项。这样您就可以轻松查看已实现/修复了哪些功能/错误。这不仅有助于了解某个版本是否包含功能或错误修复,而且还有助于轻松创建发行说明。
In the best case, a commit is bound to a work item in a feature/bug tracker. That way you will be able to easily see which feature/bug has been implemented/fixed. This is not only useful to know if a certain revision contains a feature or bug fix but also to easily create a release note.
如果没有注释告诉你它是什么,那么提交还有什么意义呢?这就像问“为什么书籍的侧面有标题?”,或者“为什么书籍有索引和页码?”。在我看来,没有对每个更改进行描述的源代码控制日志不会很有用。
您可能需要参考提交消息的原因包括
对于这两种可能性中的任何一种,如果没有良好的提交消息,您将不得不查找每个提交的差异,直到在代码中找到您要查找的内容。
What would be the point of a commit without a note to tell you what it is? It's like asking 'Why do books have titles on the sides?', or perhaps 'Why do books have indexes and page numbers?'. It seems to me that a source control log that didn't have a description for each change wouldn't be very useful.
Reasons you may need to refer to the commit message include
For either of these possibilities, without good commit messages, you would be left looking through the diffs for every single commit until you found what you were looking for in the code.