Commit Messages

Commit messages are a form of communication with other developers. As such, they should be understandable and informative, providing context for the changes that have been made. Since we use Git for version control, messages should also adhere to certain formatting conventions that make it easier to work with Git and related tools.


  1. Subject. Summarize your changes in the first line of the commit message. For very straightforward commits, this one line could be the entire message.
    • Include the most important information. Don't assume that readers can see the entire commit message; subjects often appear in isolation (e.g., GitHub history listings, git log --oneline, git shortlog).
    • Be specific. Avoid vague subjects like "Update to latest version" or "Fix the build". For example, if you are updating a port to a new upstream version, mention the version number.
    • List any modified ports first, followed by a colon (e.g., "autoconf, libtool:"). To save space, you can use glob notation (e.g., "py3*-numpy:", "clang-3.[6-9]:") or describe the ports' commonality (e.g., "boost dependents:").
    • Try to use no more than 50–55 characters, and treat 60 characters as a hard maximum. Feel free to shunt minor changes down to the message body. If you are having serious trouble meeting these limits, consider breaking up the commit into smaller pieces that are easier to describe.
  2. Blank line. Separate the subject from the body with a blank line; otherwise tools that parse Git history will get confused. Plus, it looks better.
  3. Body. Use the rest of the commit message to provide context for your changes.
    • Say what the commit itself cannot. What was the previous behavior, and why was it incorrect or suboptimal? How does your commit change that, and why did you choose this particular approach? Don't just translate the commit diff into English. (However, some context is understood and need not be pointed out. For example, we assume that updating a port to a new upstream version is beneficial. You do not have to describe the deficiencies of the old version and benefits of the new one.)
    • Use full Trac URLs. TracLinks do not work on GitHub (obviously), so refer to Trac tickets by URL instead of number (e.g., "" instead of "#12345").
    • Use autolinked references to refer to GitHub resources. The website automatically links "#n" to pull requests and SHA-1 hashes to commits.
    • Wrap body text at 72 characters. Git does not do this automatically, so hard-wrap the body to prevent text from overflowing standard-width terminal emulators. This also ensures that the output of git format-patch adheres to good email etiquette. (You can't do much about very long URLs, unfortunately.)

An example:

mutt: replace w/neomutt to reduce maint. effort

Maintaining all our patches against mutt in the ports tree is considerable
effort; now that the NeoMutt project does this for us, replace our mutt port
with neomutt to avoid wasting our time.


For more detail on general conventions for Git commit messages:


Commit messages can include keywords that trigger certain Trac actions. The keywords are case-insensitive and must be followed by the URL of a Trac ticket.

  • "References", "refs", "addresses", "re", "see": A comment is added to the referenced ticket, containing the commit message and a link to the commit.
  • "Close", "closed", "closes", "fix", "fixed", "fixes": Same as above, and the ticket is closed as "fixed". Similar keywords can be used to automatically close GitHub pull requests.
    Maintainer fixed

This functionality is provided by Clemens Lang's trac-configurable-ctu, an extension of Trac's Commit Ticket Updater.


Unlike Subversion, which stores changeset logs as mutable properties, Git commit messages are integral parts of commit objects, which are immutable. Correcting a commit's message replaces the commit and all its descendants with new commits (because every commit contains the SHA-1 hashes of its parents). This may or may not be a problem.

  • You can correct any commit you have not pushed to GitHub by amending it or doing an interactive rebase. It's good practice to review local commits before pushing them.
  • You cannot correct commits that you have already pushed. Comment on the commit's GitHub page instead. (Modifying your local history causes it to diverge from the public history. Publishing this alternate history would require force-pushing, which we disallow because it's bad practice.)

If you have a relatively recent Git, you can easily check whether a commit deadb33f is already in the history of a remote branch:

$ git fetch origin master
$ git merge-base --is-ancestor deadb33f origin/master

Text editors

When Git requires a text editor, it chooses one from the following sources, in order:

  1. the GIT_EDITOR environment variable
  2. the core.editor Git configuration variable
  3. the VISUAL environment variable
  4. the EDITOR environment variable
  5. the compile-time default (usually vi)

It is best to modify your shell startup files to set the VISUAL or EDITOR environment variables. Git requires no configuration to use them, and they can be used by other programs too.

# Bourne shell (sh) and relatives
export VISUAL
# C shell (csh) and relatives
setenv VISUAL nano

If for some reason you want to override VISUAL/EDITOR and use a different editor with Git, you can specify it in $HOME/.gitconfig:

$ git config --global core.editor ed

In case you're using vim as your favorite editor you might want to enable colorizing the commit messages according to the required formatting rules w.r.t. characters in the first and subsequent lines like this:

filetype plugin indent on
hi def link gitcommitOverflow Error

autocmd BufEnter COMMIT_EDITMSG
   \ if &textwidth > 0 |
       \ exec 'match Overlength /\%>' . &textwidth . 'v.\+/' |
   \ endif
hi def link Overlength Error
" or customize it with other colors
"hi OverLength ctermbg=LightRed guibg=LightRed

which needs to be saved in ~/.vimrc.

Last modified 2 months ago Last modified on Jan 24, 2017, 8:11:32 PM