693

I read once that git commit messages should be in the imperative present tense, e.g. "Add tests for x". I always find myself using the past tense, e.g. "Added tests for x" though, which feels a lot more natural to me.

Here's a recent John Resig commit showing the two in one message:

Tweak some more jQuery set results in the manipulation tests. Also fixed the order of the expected test results.

Does it matter? Which should I use?

13

7 Answers 7

825

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.

23
  • 112
    I think this is an excellent choice. Think about what a commit is, in diff form: a set of instructions for how to go from a previous state to a new state. Just as the diff says "add this line here, remove this line here", the commit message says in qualitative terms "make this change". (Yes, git does store the commit simply as a tree with metadata, but to a human, the important part of a commit is the diff.)
    – Cascabel
    Aug 27, 2010 at 3:11
  • 177
    You may see a commit as a set of instructions for how to go from the previous state to the new state; but I see it more as a check-point in the evolution of the code. For me, the commit message is a log of what has been done to the code since the previous commit; and for a log, past tense makes a lot more sense. If you really think the commit message should be a set of instructions, then the imperative tense is the way to go. I just really do not think of it in that way.
    – karadoc
    Jun 4, 2012 at 14:16
  • 11
    @oschrenk: Later versions of the file have given a reason: "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 behaviour."
    – mipadi
    Apr 10, 2013 at 7:21
  • 70
    The commit message should be imperative, present tense because with git you or somebody else may end up doing rebase or cherry-pick and in that case, the commit may be used outside its original context. As a result, the commit message should be written standalone without expecting reader to view any surrounding commit messages. When you're cherry picking patches, it makes more sense to apply "Fix quicksort algorithm" or "Sorting: Improve performance" instead of "Fixed bug #124" or "Modified sorting to improve performance". May 6, 2013 at 7:22
  • 11
    The way I think about this is that the message should tell me what will change if I choose to apply this commit to my branch. I don't think of it as a log but as states that I can move to and I need to know what will happen when I choose a particular state.
    – steinybot
    Nov 7, 2013 at 23:21
433

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).

18
  • 121
    I first heard today about the supposed preference for imperative style commits. To me, it sounded so unnatural and bizarre that I decided to seek some more opinions. I'm pleased to see I'm not the only one who thinks past tense is more natural for commit messages. :)
    – karadoc
    May 23, 2012 at 0:25
  • 79
    git's automatically generated merge and rebase commit messages are imperative and present tense ("Merge", not "Merged"; "Rebase", not "Rebased"), so you might want to match this in your own commit messages for consistency.
    – mjs
    Apr 16, 2013 at 16:51
  • 21
    Seems that the difference is between a focus on the change to the software - "Fixed X by doing Y" - or the repository - "Do Y to fix X." +1 for a good argument, but I think the repo should usually focus on itself rather than the resulting software.
    – l0b0
    Apr 24, 2013 at 13:40
  • 35
    The thing is, using imperative, present tense works for huge projects (e.g. Linux) so it obviously scales. In addition, it requires pretty much zero effort using over past tense. As result, I see no reason (other than "old people are used to write commit messages in past tense") to use anything else but imperative, present tense. If you can learn the git command set, you can learn writing in imperative, present tense. May 6, 2013 at 7:28
  • 48
    Imperative is not "new since git". ChangeLog existed long before git, and the use of imperative has always been the recommended style in the GNU Project. gnu.org/prep/standards/html_node/Style-of-Change-Logs.html
    – adl
    Jul 16, 2013 at 9:44
99

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.

2
  • 12
    Well, you've mixed up two different guidelines: the Git open source project, and regular usage of Git. The provided link does not mention tense at all. The official Git doc only mentions the 50 char limit. Git is a distributed VCS where there are many places to get changes from...consider these messages as the instructions for what applying the commit will do. This only applies to a few projects which are actually distributed projects. 99.999% of Git commits will never be manually applied such a manner. In most projects, the history is a change log, which should be in the past tense. Apr 17, 2013 at 0:27
  • 4
    "and should skip the full stop"
    – takeshin
    Jul 16, 2013 at 8:28
47

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."
23

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.

14

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!

6
  • 43
    To some people, things like that matter quite a bit. May 14, 2012 at 17:31
  • 3
    @mog the link does not make any statement about present and past.
    – ceving
    Mar 19, 2013 at 14:49
  • 2
    If the project does scale big time the people doing code review and bug hunting will see so many commits that they need all the help you and I can provide. There's no point saving a couple of seconds now to cause major headache in the future for not writing a proper commit message. May 6, 2013 at 7:31
  • I'm not saying don't write a good commit message. I'm saying it doesn't matter if you use past or present tense. Oct 8, 2018 at 8:20
  • 1
    How would you know, that the person not being able to interpret your commit message, is cause of that person not capable enough, or you not capable enough of writing a good commit message?
    – Haris
    Feb 22, 2019 at 17:57
11

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.