10

GitHub (probably, wrongly) uses #'s when referring to GitHub issues. So I would like to add a commit message that refers to the issue on the first line.

e.g.

#12: New commit

- Did a thing
- Did another thing

Vim/git ignores lines starting with #'s though so I'm not sure how to escape it 🤷‍♂️

1
  • 4
    It's Git, not Vim, that treats # as a comment. (Well, Vim colors text based on #-as-comment, but that does not affect the end result.)
    – torek
    Commented Jun 28, 2019 at 1:01

3 Answers 3

13

Git allows you to update the comment char from the # symbol to any other. Then you can use the # symbol.

e.g.

git config core.commentChar '>'

or optionally set it globally

git config --global core.commentchar '>'
7

The simplest way to avoid git interpreting the issue number as a comment line, is to insert another character before, so the # is not the leading character of the line (a space will do the trick).

Here is an example:

#45

will be seen as a comment

 #45
Issue #45

will both be taken entirely as commit messages

1

Try: git commit --amend -m "# ... "

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 4, 2022 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.