'How do I commit code blocks in my git commit messages
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
