'Ignore bash backtick execution without escaping the ` character in git commit [duplicate]

I use backtick character in my commits very often. I also usually commit using git commit -m

When I run a command like this

git commit -m "add `foo`"

Bash tries to execute foo.

I can use backslash \ to escape the backtick but I am wishing for a better solution to avoid escaping backtick all the time.



Solution 1:[1]

Use single quotes instead of double quotes.

git commit -m 'add `foo`'

Variables, backticks, and $(...) are expanded in double quotes, but not single quotes.

See Difference between single and double quotes in Bash

Solution 2:[2]

Back tick in shell are considered as command and are executed. If the command is not a valid one, it leaves a empty string.

Refer this Great post https://joelclermont.com/post/2021-02/backticks-in-git-commit-messages/.

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
Solution 2 Akanksha