5

Every once in a while I want to include lines that start with # in git commit messages.

The question is "Is there a way to escape the # character so that it is not interpreted as a comment mark?"

Please answer with "Yes, it is.." or "No".

This is not a duplicate of Start a git commit message with a hashmark (#). I simply want a confirmation of whether it is possible to escape or not.

joegomain
  • 536
  • 1
  • 5
  • 22

1 Answers1

5

No, it isn't possible to escape the character. If the comment character is #, and you write \#, then your commit message will contain the literal text \#.

If you need to use a different character, you can set core.commentchar to a different value. This can be done on the command line with something like git -c 'core.commentchar=;' commit.

Run this to make it a permanent preference:

git config --global --add core.commentchar ';'
djeikyb
  • 4,470
  • 3
  • 35
  • 42
bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thank you. I had a strong feeling it would be a no. But none of the answers on this topic spelled it out. And thanks for the `-c` tip. – joegomain Nov 22 '20 at 19:50