Skip to content

Writing a commit message

Erik Nyquist edited this page Jan 6, 2017 · 23 revisions

A good commit message should have two basic parts; a subject, and a description (if required). The subject is always on the first line (and only the first line), and the description is always separated from the subject with a blank line.

<Subject: brief one-liner describing your changes>

<Description: if more detail is needed, then skip a line
and put it in the description. However, if you don't think
you need it, then a one-line commit message is OK>

Additionally:

  • The subject line should be no longer than 72 characters. Lines in the description should be no longer than 80 characters.
  • Always use imperative mood for commit messages, as if you are commanding the code to change its behaviour; instead of saying "I added a new feature" and "I fixed the bug", say "Add a new feature" and "Fix the bug".
  • Make sure your commit message contains an accurate summary of your changes (for example, "Made some improvements" is a bad commit message). If you're finding it difficult to summarise your changes in one short commit message, then perhaps you should consider breaking the change up into multiple commits, within reason (i.e. no broken commits-- every commit should compile and be functional).

Some examples of bad commit messages (Using a fictional I2C library as an example):

commit a6e149dfea1c8288714c90cbb26fed78022bac3b
Author: John Smith <john.smith@madeup.com>
Date:   Sun Jan 6 01:04:46 1991 +0000

    I2C library fixes

    This fixes some of the recent errors that have been happening in the I2C library



commit 41fdaf8df10cd6d16b96535b206b28c63345ef37
Author: Jane Doe <jane.doe@fake.org>
Date:   Thu Dec 19 15:28:02 1991 +0000

    update README

LIBRARY UPDATE COMMIT`

fix for bug #334

various fixes for I2C library

Some examples of good commit messages (Using the same fictional I2C library):

libs/I2C/I2C.c: handle null pointer in i2c_getbytes()

Add documentation URLs to I2C library README file

Upgrade I2C library version number to 0.5

I2C.h: Remove unused value in i2c_controller struct

Clone this wiki locally