4

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?

John McFarlane
  • 5,528
  • 4
  • 34
  • 38
wullxz
  • 17,830
  • 8
  • 32
  • 51

2 Answers2

5

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

joran
  • 2,815
  • 16
  • 18
  • thanks! no idea how i could've missed that when i searched for something like that. i wish there was an argument that would still strip comments but would leave the whitespaces where they are. i'm using a `commit-msg` hook for comment stripping now. do you have a better idea? – wullxz Sep 06 '15 at 03:07
1

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).

John McFarlane
  • 5,528
  • 4
  • 34
  • 38