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
- Message or Title – Recommended length is 50 character. This is a short summary of about your git change.
- 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
- https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
- https://stackoverflow.com/questions/2290016/git-commit-messages-50-72-formatting
- https://www.baeldung.com/linux/vim-find-full-path-current-file
- https://vi.stackexchange.com/questions/27501/default-rulerformat
- https://vimhelp.org/options.txt.html#%27rulerformat%27
- https://codeyarns.com/tech/2010-11-28-vim-ruler-and-default-ruler-format.html
- https://initialcommit.com/blog/git-commit-messages-best-practices
- https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/