gitgit-notes

When editting git notes, lines start with # disappear?


If I use git notes --ref=$REF edit $COMMIT,original message is:

Notes (xxx):

#NEW

path/to/file1: your message

path/to/file2: your message

#TEST

path/to/file3: your message

then the message becomes

Notes (xxx):

path/to/file1: your message

path/to/file2: your message

path/to/file3: your message

How to avoid that? I want to keep "#".


Solution

  • If you take a look at builtin/notes.c in Git, you will see that it calls stripspace(&(msg->buf), 1); if it calls an editor, but stripspace(&(msg->buf), 0); if the message is passed in on the command line or via a file. stripspace(..., 1); means "skip comments", which causes it to strip out comments as well (lines starting with #), while stripspace(..., 0) means "don't skip comments", so they will be included.

    So it looks like the best way to create notes including a # at the beginning of a line is to pass the note in via -m 'note contents' on the command line or -F filename to read the note in from a file.

    This applies to the latest version of the code in git.git; I've tested with 1.8.0.