Skip to content

Instantly share code, notes, and snippets.

@gusano
Created January 10, 2014 13:42
Show Gist options
  • Save gusano/8352114 to your computer and use it in GitHub Desktop.
Save gusano/8352114 to your computer and use it in GitHub Desktop.
Git commit messages best practises

Inspired from https://github.com/git/git/blob/master/Documentation/SubmittingPatches

Table of content

Describe your changes well

The first line of the commit message should be a short description (50 characters is the soft limit), and should skip the full stop.

It is also conventional in most cases to prefix the first line with "area: " where the area is a filename or identifier for the general area of the code being modified, e.g.

  • LoginController: throw Exception if $userId is missing
  • readme.md: clarify the use of API

The body should provide a meaningful commit message, which:

  • explains the problem the change tries to solve, iow, what is wrong with the current code without the change.

  • justifies the way the change solves the problem, iow, why the result with the change is better.

  • alternate solutions considered but discarded, if any.

Describe your changes in imperative mood

e.g. make xyzzy do frotz instead of [This patch] makes xyzzy do frotz or Changed xyzzy to do frotz, as if you are giving orders to the codebase to change its behaviour.

A perfect example would be something like:

AdminController: better handling of course/lesson deletion

- don't pretend a Course has Lessons when any Exception is thrown
- if an Exception happens, display it
- if a Course has Lessons, display the correct error message
- don't test against user role as Acl takes care of that alread

Why

This greatly improves reviewing patches, as well as helping other developers to quickly find where changes happened to a certain area of the code, etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment