Search code examples
gitcomments

Is it possible to escape the hash(#) comment charactor in git commit messages?


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.


Solution

  • 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 ';'