Prabhakar Kasi iOS Developer, Front End Developer

Recommended Git commit message format

1 min read

It is a good practice to write a detailed git commit message but very often we don’t write proper message but whenever we do not many follow a well defined format. Based on my reading and also peer feedback it is recommended to follow 50/72 Formatting while writing a git message.

Git Message have two parts

  1. Message or Title – Recommended length is 50 character. This is a short summary of about your git change.
  2. Detailed message – Recommended length is 72 per line. This is a detailed summary of what, why and how this change was done.
TICKET-123 MESSAGE (50 characters)

DETAILED MESSAGE GOES HERE (72 characters per line)

Avoid using this style of commit message

git commit -m "commit message"

Always use

git commit

If you have configured the default text editor for git, then the editor would open up.

git config --global core.editor vi

For vim and vi, we can make use of “:set textwidth=72” to configure the editor to automatically break line when the column counts reaches 72 in a line as you keep typing. This won’t break words so if you really have a long word/string greater than 72 characters, like for e.g., – URL that is over 72 characters would be allowed as it is.

vi ~/.vimrc

# Append these config
" Force to show status line always
set laststatus=2
" Turn syntax highlighting on.
syntax on
" Setting max text width per line. 
" This will automatically create new line when the cursor reaches 72
set tw=72
" Shows the line number and the column number in bottom status line
set ruler
" Default ruler format show line number and column number
" %17 -> Ruler length or width. Default value is 17
" %l -> line number, %c -> column number,
" %V -> virtual (or screen) column, matters for TAB and multibyte chars
" %p -> Percent value of position of cursor in the file. 
set rulerformat=%17(%l,%c%V\ %p%%%)

If you are using tmux or screen then you might need slightly different settings.

Reference

  1. https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
  2. https://stackoverflow.com/questions/2290016/git-commit-messages-50-72-formatting
  3. https://www.baeldung.com/linux/vim-find-full-path-current-file
  4. https://vi.stackexchange.com/questions/27501/default-rulerformat
  5. https://vimhelp.org/options.txt.html#%27rulerformat%27
  6. https://codeyarns.com/tech/2010-11-28-vim-ruler-and-default-ruler-format.html
  7. https://initialcommit.com/blog/git-commit-messages-best-practices
  8. https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/
Prabhakar Kasi iOS Developer, Front End Developer

Leave a Reply