Elliott Elliott - 3 years ago 104
Git Question

What does git core.commentChar=auto do?

I'm testing

git commentChar=auto
for a library that must emulate
for some purposes.

If I run
git commit -m "#message"
, and then make a second commit which open the editor to edit the message,
comments are still marked by
. Why is this?

According to the docs:


Commands such as commit and tag that let you edit
messages consider a line that begins with this character commented,
and removes them after the editor returns (default #).

If set to "auto", git-commit would select a character that is not the
beginning character of any line in existing commit messages.

But when I run a test script:

git config --global core.commentChar auto
touch foo
git add foo
git commit -m '#message'
touch bar
git add bar
git commit # opens editor, And I see:

# Please enter the commit message // Wrong! This should not use the # char.

Answer Source

From some tests in the git repo it only applies this "auto" methodology if the message it is "commenting" about already contains a comment character. The existing commit messages in the docs refer to (in this case) the amended message (or in the case of a rebase-squash the several commit messages).

You can see the way this is handled in commit.c: here

It looks at the current buffer that is about to be displayed and picks the first of "#;@!$%^&|:" as potential comment characters and otherwise errors.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download