My problem
While writing a commit message, I tried to use the " ` " mark to format the message with code.
This is my commit message:
git commit -am"style(Nav.tsx): adheres to eslint rules line 92 and 122: add `@returns` in docstrings" After I execute the command, I get this
bash: @returns: command not found [auth 57ee20c] style(Nav.tsx): adheres to eslint rules 1 file changed, 27 insertions(+), 6 deletions(-) And the commit message cuts off. On GitHub, the line in question looks like this
line 92 and 122: add in docstrings What I have tried
I have tried using three of the " ` " thingies and I have also tried using <code></code>
When I use "", I get the same message and problem, and when I use <code></code>, the command not found error is gone, but the commit message retains the <code></code> blocks instead of converting it. I have also tried string escaping like this
line 92 and 122: add \`@returns\` in docstrings And the like the code blocks, the commit message retains the " ` " instead of converting it.
12 Answers
In Bash, double-quoted strings are subject to command substitution*. That's what the backticks are doing in the first case, and why you're seeing bash: @returns: command not found. To fix it, you can escape them, like you did:
git commit -am "style(Nav.tsx): adheres to eslint rules ... line 92 and 122: add \`@returns\` in docstrings" or use single quotes:
git commit -am 'style(Nav.tsx): adheres to eslint rules ... line 92 and 122: add `@returns` in docstrings' But, the backticks will be retained. Commit messages are plain text. The fancy formatting in that screenshot is being done by GitHub, not git. I believe GitHub supports Markdown in commit messages. (Stack Exchange also uses Markdown.)
* BTW if you did want to do command substitution in Bash, you should use the new syntax, $(command) instead of `command`.
What probably happened
Your shell (probably bash or some bourne shell variant) has a feature to execute commands and use the result to build a new command line. One of the ways to access that feature is by backticks. You can e.g. do
echo "Today is `date`." to show the output of date within a nice little sentence.
What you can do instead to have ` in your commit message
Use single quotes (
') around the message argument. Bash and sh don't perform command substitution in single-quoted strings.or
- Compose the commit message in an editor, rather than passing it on the command line. Do so by omitting the
-moption and its argument. Git will then open the editor specified by the environment variable$EDITORto let you edit the commit message.
Commit messages are plain text
To Git and its command line tools (e.g. git log), commit messages are plain text, without any markup language. Hosting platforms like GitHub and third-party tools may interpret that plain text as some markup language in some context, but not necessarily in all contexts. Wherever GitHub does that, it'll usually be interpreting it as GitHub flavored MarkDown.