提交消息应该用现在时还是过去时写?

那么,你认为哪一种更好,哪一种更直观呢?

Fixed the XXX bug in YYY
Fix the XXX bug in YYY
Fixes the XXX bug in YYY
Fixing the XXX bug in YYY

请提供你的理由。请注意,我是从您的一般角度提出这个问题的,这意味着您不应该试图将它与您首选的 svn/cvs 工具或编程语言联系起来,而应该将其视为应该/可以应用于任何工具和编程语言的东西。

10136 次浏览

I don't think it really matters. The purpose is to:

1) Convey what is or was being done, so bugs can be found easier, problems can be reverted easier, and generally be able to maintain the project easier.

2) Convey what tickets were fixed if any, so auditors (if they're used in you company can see what changes correspond to which tickets).

Lastly, if it's' already been fixed, "Fixing" doesn't make sense, and if you're still working on it, "Fixed" isn't correct.

I personally go with past tense ("fixed") since by the time I get to committing the bug is fixed (or I wouldn't be committing).

I think that writing about the current commit in present tense is a good idea, because it makes it more clear when you refer to prior commits in the past tense.

I think of these messages as they appear to other developers. They don't yet have the changes applied, and there is the implicit question, "what will applying this changeset/patch do?" It will "Fix the XXX bug in YYY"!

For other verbs writing them as a command seems more natural, and works better if you have a specific goal up-front—you can literally write the commit summary along with up-front tests before the work is done.

I don't put a huge amount of weight on it, but for me this is the path of least resistance while maintaining consistentency.

If it is a small commit I use present continuous:

Fixing bug 304

or

Adding comments

If it is a big commit, I do more of a change log:

  • Fixes Bug 453, 657 and 324
  • Adding Expression syntax
  • Refactored the Operator class.

"Fix bug X" is 2 characters shorter than "Fixed bug X".
And 3 shorter than "Fixing bug X".

From the point of view of writing-short-commit-messages, the present tense sometimes / usually saves a few characters?
Which I actually think matters a little little bit e.g. with Git's recommendation of less-than-50-chars-on-the-first-commit-message-line.
Also, less text --> done reading quicker?

IMHO if you want it to be descriptive without need to consider the context, then "Fixed" is definitely the only right variant.

Regarding the intuitiveness - if I look at some changelog I will definitely understand that you mean the bug fixed as I know the context in which the word is used, but my brain will catch it much more quickly if the word is written in this self-specifying way.

"Fixing" is the worst choice IMHO as it can be interpreted not only as describing what the patch does (is for) but as a bug status as well which would mean that it is being worked at and is not yet solved.

Fix the XXX bug in YYY
Teach the XXX to be more ZZZ
Correct typos in javadoc

In general: {imperative verb} the {affected object} {optional qualifiers}

Imperative form fits all use cases when I'm considering a patchset.

  • What are you going to do here?
  • What does this patchset do?
  • Why was this patchset created? (to fix the xxx bug...)
  • I need to fix the xxx bug in yyy. Is there a commit on another branch that does this already?

Regardless of your choice, I find consistency helps readability immensely. Pick one and stick with it.

I prefer to see commit messages in present tense. That way the message describes what the diff does (because you might pull that diff or even that whole commit into a different branch). Thus, the commit message does not describe what it "did" do... It describes what the commit itself "does" do. So it should be in present tense.

Imagine looking at a diff in isolation and trying to decide whether you will apply it. It makes no sense for it to have a title in the past tense.

A commit message describes why you wrote the code that is being committed.

"Fixed issue 3124", or "Fixes issue 3124" seems right because it says this code fixed|fixes issue 3124.

However, the grammar may also depend on why marks the bug as fixed. If you can mark the bug as fixed after committing, then "Fixed" is just fine, but if the bug is going to be marked as fixed by someone else after they verify your code, then "Fixes" may be more appropriate.

I think the most important answer to such a question is: Everybody should use what works for a specific project and keep it at least a tiny bit consistent.

While I see the advantages of using the present tense (and in fact stumbled upon this post because I’ve seen some present tense messages in open source projects), I probably never won’t use the present tense for my projects. It’s the recommended way for Linux and Git, and probably other bigger open source projects, but I honestly don’t care as long as I’m not part of these projects.

I’m an indie dev and I use the first line of a commit message for release notes while the description in the following lines gives me an idea about implementation details. It’s a user centric workflow compared to the present tense, developer based approach. I can save some time this way. It would be extremely unnatural to give my users instructions in the release notes. It’s my job to fix bugs and to add features. I have to save time, because I’m an indie. I don’t have a “release notes writer” in my team.

Use the rules of a project if they’re already established, but stay pragmatic, and do whatever will make your work easier or faster.

I think "Fixes XXX bug" makes more sense than "Fix XXX bug" if the reason for using the present tense is to "make it more descriptive of what the commit does" rather than what the committer did.