git
commit messages
past tense
present tense
software development

Should I use past or present tense in git commit messages?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Git commit messages play a crucial role in the software development lifecycle. They serve as the primary method for developers to document changes, reasons for the update, and the impact on the overall project. When crafting effective commit messages, developers often grapple with the choice between using the past or present tense. This might seem like an inconsequential detail, but it can impact the clarity and consistency of project documentation.

The Role of Verb Tense in Commit Messages

The choice of verb tense in commit messages should lean toward enhancing clarity, readability, and consistency. Let’s explore some technical guidelines and best practices regarding verb tenses:

Present Tense: The Preferred Style

Using the present tense in commit messages is often preferred within the developer community. There are several reasons for this choice:

  1. Action-Oriented Documentation: Commit messages describe what the commit does, rather than what was done. This aligns with the commit being a snapshot of the current state. For example, a message like `"Add login authentication"` is direct and concise.
  2. Brevity and Directness: Present tense inherently encourages brevity. It allows developers to convey changes without unnecessary words, making each message precise and to the point. Consider `"Fix bug in user profile"` versus `"Fixed a bug in the user profile"`. The former is shorter and more direct.
  3. Consistency with Other Documentation: Many other forms of technical documentation, such as code comments or issue descriptions, often use the present tense to describe behavior and functionalities.
  4. Explanatory Consistency: When reviewing commit history, using the present tense provides a uniform way to understand each change as an active modification, helping new developers or collaborators quickly digest the changes.

Past Tense: When is it Appropriate?

While the present tense dominates guidelines and practices, there are scenarios where using the past tense can be suitable:

  1. Historical Context: When a commit message is meant to provide historical context or when documenting the resolution of a significant issue, using the past tense may be more appropriate. For example, `"Resolved issue with database connection"` explicitly denotes that the problem was tackled before this commit.
  2. Project-Specific Conventions: Some development teams or organizations might have their own documentation conventions that prefer the past tense to ensure consistency with other parts of the project logs.

Conditional Recommendations

In some cases, neither the present nor past tense is strictly required. Developers can pair tense with other verbs to achieve nuanced meanings:

  • Use of Infinitive Forms: Using commands like `"To update API endpoints for improved performance"` provides both an intention and action without ambiguity.
  • Gerunds for Ongoing Changes: Phrases like `"Refactoring payment gateway"` effectively captures ongoing work, especially in a work-in-progress branch.

Best Practices and Examples

To understand how to structure commit messages effectively, here are some examples:

Message FormatExampleContext/Explanation
Present TenseFix email verification endpointCurrent action described directly; accepted standard.
Past TenseCorrected typos in documentationDescribing a previous change for historical context.
InfinitiveTo enhance search functionalityIntent-focused message indicating future impact.
GerundRefactoring module to ES6 syntaxOngoing action typically in WIP (Work In Progress) branch.

Conclusion

The choice between present and past tense in Git commit messages ultimately depends on the norms of the team and the purpose of the message. However, the present tense is generally recommended as it aligns with the notion of describing the "state change" in the repository. It maintains a level of consistency that aids in both reading and maintaining project histories. Adhering to a single style within a project helps improve communication and alignment among development teams, ensuring that the version control system remains a robust asset.

While technical considerations and organizational standards may affect the usage, ensuring clarity and brevity should be at the forefront of crafting effective commit messages. The verb tense chosen should serve to enhance the message's goal—clearly communicating the nature and purpose of the change to current and future readers.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions