Get sublime help with git commit messages

  1. Use Sublime Text – my preferred text editor
  2. Configure git to use Sublime Text to edit commit messages by:
    • git config --global --replace-all core.editor "subl -w" (on macOS)
    • git config --global --replace-all core.editor "'C:/Program Files/Sublime Text 3/subl.exe' -w" (on Windows)
  3. Install the Sublime Text Package Git Commit Message Syntax which will add file type detection and syntax highlighting for files named COMMIT_EDITMSG, which is what git uses.
  4. Open the settings for that syntax;
    • Open ~/Library/Application Support/Sublime Text 3/Packages/User/commit-message.sublime-settings (on macOS), or
    • Either use git to open a commit message, or set the current syntax to Commit Message, and go to Preferences > Settings – Syntax Specific (which opens up the settings file specific to the current syntax)
  5. Add rulers for the recommended commit message lengths by adding
    "rulers":[72, 50] between the curly brackets, and save the file.

Now, when writing a commit message, these rulers will help you visually keep the first line (the commit title) around 50 characters long, and the commit body around 72 characters.

A bonus feature is that using the command Edit > Wrap > Wrap Paragraph at Ruler, will now reformat the current paragraph to wrap along the first ruler (72), which makes it really easy to keep longer commit messages nicely formatted without manual fiddling!

Leave a Reply

Close Menu