Start a git commit message with a hashmark (#)

Note that, since git1.8.2 (February 2013), you can use a different character than '#' for the commented line in the commit message.

That allows you to use '#' for your bug number reference.

Various "hint" lines Git gives when it asks the user to edit messages in the editor are commented out with '#' by default.

The core.commentChar configuration variable can be used to customize this '#' to a different character.


In theory, you could put a core.commentChar word (multiple characters), but git 2.0.x/2.1 will be stricter (Q3 2014).

See commit 50b54fd by Nguyễn Thái Ngọc Duy (pclouds):

config: be strict on core.commentChar

We don't support comment strings (at least not yet). And multi-byte character encoding could also be misinterpreted.

The test with two commas is updated because it violates this. It's added with the patch that introduces core.commentChar in eff80a9 (Allow custom "comment char" - 2013-01-16). It's not clear to me why that behavior is wanted.


git 2.0.x/2.1 (Q3 2014) will add an automatic selection for core.commentChar:
See commit 84c9dc2

When core.commentChar is "auto", the comment char starts with '#' as in default but if it's already in the prepared message, find another char in a small subset. This should stop surprises because git strips some lines unexpectedly.

Note that git is not smart enough to recognize '#' as the comment char in custom templates and convert it if the final comment char is different.
It thinks '#' lines in custom templates as part of the commit message. So don't use this with custom templates.

The list of candidate characters for "auto" are:

# ; @ ! $ % ^ & | :

That means a command like git commit -m '#1 fixed issue' will automatically switch the commentChar to ';', because '#' was used in the commit message.


This behaviour is part of git commit's default 'clean-up' behaviour. If you want to keep lines starting with # you can use an alternative clean-up mode.

E.g.

git commit --cleanup=whitespace

If you do this you have to be careful to remove all # lines that you don't want to appear in the commit.