我应该在 git 提交消息中使用过去时还是现在时?

发布于 2024-09-16 04:31:00 字数 1432 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

Oo萌小芽oO 2024-09-23 04:31:00

对现在时、命令式提交消息的偏好来自 Git 本身。来自 文档/SubmittingPatches< /a> 在 Git 存储库中:

描述您在祈使语气中的变化,例如“make xyzzy do frtz”
而不是“[这个补丁]使 xyzzy 变得 frotz”或“[I]改变了 xyzzy
进行 frotz”,就好像您正在向代码库发出更改命令
它的行为。

所以你会看到很多以这种风格编写的 Git 提交消息。如果您在团队中工作或在开源软件上工作,那么每个人都坚持这种风格以保持一致性会很有帮助。即使您正在开发一个私人项目,并且您是唯一一个能够看到您的 git 历史记录的人,使用命令语气也会很有帮助,因为它会建立良好的习惯,当您与其他人一起工作时,这些习惯会受到赞赏。

The preference for present-tense, imperative-style commit messages comes from Git itself. From Documentation/SubmittingPatches in the Git repo:

Describe your changes in imperative mood, e.g. "make xyzzy do frotz"
instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy
to do frotz", as if you are giving orders to the codebase to change
its behavior.

So you'll see a lot of Git commit messages written in that style. If you're working on a team or on open source software, it is helpful if everyone sticks to that style for consistency. Even if you're working on a private project, and you're the only one who will ever see your git history, it's helpful to use the imperative mood because it establishes good habits that will be appreciated when you're working with others.

永言不败 2024-09-23 04:31:00

您的项目应该几乎总是使用过去时。无论如何,项目应始终使用相同的时态,以保持一致性和清晰度。

我理解其他一些主张使用现在时的论点,但它们通常不适用。以下要点是用现在时写作的常见论点以及我的回应。

  • 用现在时写作告诉某人应用提交会做什么,而不是你做了什么。

这是人们想要使用现在时的最正确原因,但前提是项目风格正确。这种思维方式将所有提交视为可选的改进或功能,您可以自由决定在特定存储库中保留哪些提交以及拒绝哪些提交。

如果您正在处理真正的分布式项目,那么这个论点就有效。如果您正在处理分布式项目,那么您可能正在处理开源项目。而且如果真的分布式的话,可能是一个非常大的项目。事实上,它可能是 Linux 内核或 Git。由于 Linux 很可能是 Git 传播和流行的原因,因此很容易理解为什么人们会认为它的风格具有权威性。是的,这两个项目的风格很有意义。或者,一般来说,它适用于大型、开源、分布式项目。

话虽如此,大多数源代码控制项目并不是这样工作的。对于大多数存储库来说,它通常是不正确的。这是一种思考提交的现代方式:Subversion (SVN) 和 CVS 存储库几乎无法支持这种类型的存储库签入。通常,集成分支会处理过滤不良签入的问题,但这些通常不被视为“可选”或“值得拥有的功能”。

在大多数情况下,当您向源存储库进行提交时,您正在编写一个日志条目来描述此更新所更改的内容,以便其他人将来更容易理解为何进行更改。它通常不是一个可选的更改 - 项目中的其他人需要合并或重新建立基础。您不会写诸如“亲爱的日记,今天我遇到一个男孩,他向我打招呼。”这样的日记条目,而是写“我” >遇到一个男孩,他向我打招呼。”

最后,对于此类非分布式项目,人们阅读提交消息的 99.99% 时间都是为了阅读历史记录 - 历史记录是用过去时态读取的。 0.01% 的时间将决定他们是否应该应用此提交或将其集成到他们的分支/存储库中。

  • 一致性。许多项目(包括 git 本身)都是如此。生成提交的 git 工具(如 git merge 或 git revert)也可以做到这一点。

不,我向你保证,大多数曾经登录过版本控制系统的项目都有过去时态的历史(我没有参考资料,但这可能是对的,考虑到现在时态的说法自 Git 以来是新的)。现在时的“修订”消息或提交消息只有在真正的分布式项目中才开始有意义 - 请参阅上面的第一点。

  • 人们不仅阅读历史来了解“这个代码库发生了什么”,而且还回答诸如“当我挑选这个提交时会发生什么”,或者“由于这些提交,我的代码库会发生什么样的新事情”之类的问题我将来可能合并也可能不合并”。

参见第一点。一个人阅读提交消息的 99.99% 的时间都是为了阅读历史 - 历史是以过去时态阅读的。 0.01% 的时间将决定他们是否应该应用此提交或将其集成到他们的分支/存储库中。 99.99% 胜过 0.01%。

  • 它通常更短

我从来没有见过一个好的论点说使用不正确的时态/语法,因为它更短。对于标准的 50 个字符的消息,您可能平均只能节省 3 个字符。话虽这么说,现在时态平均可能会短几个字符。

  • 您可以将提交的名称与问题/功能跟踪器中的票证标题更加一致(不使用过去时,尽管有时使用将来时)

票证可以写为当前正在发生的事情(例如应用程序正在显示 单击此按钮时的错误行为),或将来需要完成的操作(例如,文本将需要由编辑器审阅)。

历史记录(即提交消息)被写为过去完成的事情(例如问题已修复)。

Your project should almost always use the past tense. In any case, the project should always use the same tense for consistency and clarity.

I understand some of the other arguments arguing to use the present tense, but they usually don't apply. The following bullet points are common arguments for writing in the present tense, and my response.

  • Writing in the present tense tells someone what applying the commit will do, rather than what you did.

This is the most correct reason one would want to use the present tense, but only with the right style of project. This manner of thinking considers all commits as optional improvements or features, and you are free to decide which commits to keep and which to reject in your particular repository.

This argument works if you are dealing with a truly distributed project. If you are dealing with a distributed project, you are probably working on an open source project. And it is probably a very large project if it is really distributed. In fact, it's probably either the Linux kernel or Git. Since Linux is likely what caused Git to spread and gain in popularity, it's easy to understand why people would consider its style the authority. Yes, the style makes sense with those two projects. Or, in general, it works with large, open source, distributed projects.

That being said, most projects in source control do not work like this. It is usually incorrect for most repositories. It's a modern way of thinking about a commits: Subversion (SVN) and CVS repositories could barely support this style of repository check-ins. Usually an integration branch handled filtering bad check-ins, but those generally weren't considered "optional" or "nice-to-have features".

In most scenarios, when you are making commits to a source repository, you are writing a journal entry which describes what changed with this update, to make it easier for others in the future to understand why a change was made. It generally isn't an optional change - other people in the project are required to either merge or rebase on it. You don't write a diary entry such as "Dear diary, today I meet a boy and he says hello to me.", but instead you write "I met a boy and he said hello to me."

Finally, for such non-distributed projects, 99.99% of the time a person will be reading a commit message is for reading history - history is read in the past tense. 0.01% of the time it will be deciding whether or not they should apply this commit or integrate it into their branch/repository.

  • Consistency. That's how it is in many projects (including git itself). Also git tools that generate commits (like git merge or git revert) do it.

No, I guarantee you that the majority of projects ever logged in a version control system have had their history in the past tense (I don't have references, but it's probably right, considering the present tense argument is new since Git). "Revision" messages or commit messages in the present tense only started making sense in truly distributed projects - see the first point above.

  • People not only read history to know "what happened to this codebase", but also to answer questions like "what happens when I cherry-pick this commit", or "what kind of new things will happen to my code base because of these commits I may or may not merge in the future".

See the first point. 99.99% of the time a person will be reading a commit message is for reading history - history is read in the past tense. 0.01% of the time it will be deciding whether or not they should apply this commit or integrate it into their branch/repository. 99.99% beats 0.01%.

  • It's usually shorter

I've never seen a good argument that says use improper tense/grammar because it's shorter. You'll probably only save 3 characters on average for a standard 50 character message. That being said, the present tense on average will probably be a few characters shorter.

  • You can name commits more consistently with titles of tickets in your issue/feature tracker (which don't use past tense, although sometimes future)

Tickets are written as either something that is currently happening (e.g. the app is showing the wrong behavior when I click this button), or something that needs to be done in the future (e.g. the text will need a review by the editor).

History (i.e. commit messages) is written as something that was done in the past (e.g. the problem was fixed).

我家小可爱 2024-09-23 04:31:00

我在 365git 上写了更完整的描述。

祈使式现在时的使用需要一点时间
习惯了。当我开始提到它时,人们遇到了
反抗。通常沿着“提交消息记录
我做了什么”。但是,Git 是一个分布式版本控制系统
可能有很多地方可以从中获取更改。相当
而不是写一些信息来说明你所做的事情;考虑这些
消息作为应用提交将执行的操作的说明。
而不是使用标题进行提交:

<块引用>

重命名了 iVar 并删除了公共前缀。

有一个这样的:

<块引用>

重命名 iVar 以删除公共前缀

这告诉某人应用提交会做什么,而不是做什么
你做到了。另外,如果您查看存储库历史记录,您会看到
Git 生成的消息也是用这种时态编写的 -
“Merge”不是“Merged”,“Rebase”不是“Rebased”,所以写在同一个
时态使事情保持一致。一开始感觉很奇怪,但确实如此
有意义(申请后可获得推荐)并最终
变得自然。

话虽如此 - 这是你的代码,你的存储库:所以设置你的
自己的指导方针并坚持下去。

但是,如果您确实决定采用这种方式,则使用 git rebase -i
改写选项将是一件值得研究的好事情。

I wrote a fuller description on 365git.

The use of the imperative, present tense is one that takes a little
getting used to. When I started mentioning it, it was met with
resistance. Usually along the lines of “The commit message records
what I have done”. But, Git is a distributed version control system
where there are potentially many places to get changes from. Rather
than writing messages that say what you’ve done; consider these
messages as the instructions for what applying the commit will do.
Rather than having a commit with the title:

Renamed the iVars and removed the common prefix.

Have one like this:

Rename the iVars to remove the common prefix

Which tells someone what applying the commit will do, rather than what
you did. Also, if you look at your repository history you will see
that the Git generated messages are written in this tense as well -
“Merge” not “Merged”, “Rebase” not “Rebased” so writing in the same
tense keeps things consistent. It feels strange at first but it does
make sense (testimonials available upon application) and eventually
becomes natural.

Having said all that - it’s your code, your repository: so set up your
own guidelines and stick to them.

If, however, you do decide to go this way then git rebase -i with the
reword option would be a good thing to look into.

胡大本事 2024-09-23 04:31:00

坚持使用现在时势在必行,因为

  • 有一个与
  • 错误跟踪器中的票相匹配的标准是件好事,这些票自然具有“实施某事”、“修复某事”或“测试某事”的形式。

Stick with the present tense imperative because

  • it's good to have a standard
  • it matches tickets in the bug tracker which naturally have the form "implement something", "fix something", or "test something."
可遇━不可求 2024-09-23 04:31:00

您为谁写这条消息?该读者通常是在拥有提交之前还是之后阅读消息?

我认为这里从两个角度都给出了很好的答案,我可能无法建议每个项目都有一个最佳答案。分裂投票可能也表明了这一点。

即总结一下:

  • 该消息是否主要针对其他人,通常在他们进行更改之前的某个时候阅读:关于进行更改将对他们现有代码产生什么影响的建议。

  • 该消息主要是作为您自己(或您的团队)的日记/记录,但通常是从假设发生变化并回溯以发现发生了什么的角度进行阅读。

不管怎样,这也许会激发你的团队/项目的动力。

Who are you writing the message for? And is that reader typically reading the message pre- or post- ownership the commit themselves?

I think good answers here have been given from both perspectives, I’d perhaps just fall short of suggesting there is a best answer for every project. The split vote might suggest as much.

i.e. to summarise:

  • Is the message predominantly for other people, typically reading at some point before they have assumed the change: A proposal of what taking the change will do to their existing code.

  • Is the message predominantly as a journal/record to yourself (or to your team), but typically reading from the perspective of having assumed the change and searching back to discover what happened.

Perhaps this will lead the motivation for your team/project, either way.

冷弦 2024-09-23 04:31:00

这有关系吗?人们通常足够聪明,能够正确解释消息,如果他们不聪明,您可能无论如何都不应该让他们访问您的存储库!

does it matter? people are generally smart enough to interpret messages correctly, if they aren't you probably shouldn't let them access your repository anyway!

在你怀里撒娇 2024-09-23 04:31:00

这取决于你。只需根据需要使用提交消息即可。
但如果您不在时间和语言之间切换,那就更容易了。

如果您在团队中开发,则应该对其进行讨论并进行修复。

It is up to you. Just use the commit message as you wish.
But it is easier if you are not switching between times and languages.

And if you develop in a team - it should be discussed and set fixed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文