Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do not remove whitespace in git commit messages

I'm writing commit messages with vim on both my linux and my windows computers.
I'm using Bitbucket and GitHub as my repositories and would like to use some markup in commit messages to properly show the text in issues I link in my commits.

Now the problem is, that git removes those trailing whitespaces I usually use to achieve a newline on GitHub and Bitbucket.

Can this behaviour be altered? I've already searched the Git documentation but sadly didn't found anything.
What can I do to use some (or all) markups, but especially the 2-trailing-whitespaces one, in commits?

like image 498
wullxz Avatar asked Oct 18 '25 04:10

wullxz


2 Answers

If you include --cleanup=verbatim when you do a commit the message will not be altered (or add it to the config with git config add commit.cleanup verbatim).

For more info git help commit and git help config

like image 73
joran Avatar answered Oct 19 '25 18:10

joran


As you note, none of the five choices for the --cleanup option strip the commentary lines while also preserving trailing whitespace. As an alternative, commonmark allows a backslash for hard line breaks, which are always preserved in commit messages:

first line\
second line

This uglifies your git history slightly but it should display correctly on GitHub (example).

like image 20
John McFarlane Avatar answered Oct 19 '25 19:10

John McFarlane