Question

I have set mcedit as my editor for git commit messages. By default it ignores any lines starting with the # character. However odd this may seem, I need to be able to have the my commit message looking like this:

#FOO-123: Implement bar foo

Committing work in progress

The #FOO-123: ... is actually the key + title of an issue in our tracker. The tracker can automatically pick up these commit messages and add them to the issue.

Unfortunately, the first line gets treated like a comment and gets ignored.

I don't want to have to be committing from the command line by adding -m as it's inconvenient/ugly when you have multiple lines.

How could I work around this?

Was it helpful?

Solution

You can try and define a different character for comments in commit message:

git config core.commentchar <another char>

As I mention in "Start a git commit message with a hashmark (#)", this setting is available since git 1.8.2 (February 2013).

In your case:

git config core.commentchar "*"

Note that you could in theory put a core.commentchar word (multiple characters), but git 2.0.x/2.1 will be stricter.

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.


poke also mentions in the comments to change the commit template:

When editing the commit message, start the editor with the contents in the given file.
The commit.template configuration variable is often used to give this option implicitly to the command.


Note that Git 2.23 (Q3 2019) fixes a bug, as "git interpret-trailers" always treated '#' as the comment character, regardless of core.commentChar setting, which has been corrected.

See commit 29c83fc (19 Jun 2019) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 3a50607, 09 Jul 2019)

interpret-trailers: load default config

The interpret-trailers program does not do the usual loading of config via git_default_config(), and thus does not respect many of the usual options.
In particular, we will not load core.commentChar, even though the underlying trailer code uses its value.

This can be seen in the accompanying test, where setting core.commentChar to anything besides "#" results in a failure to treat the comments correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top