36

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.

codeforester
  • 39,467
  • 16
  • 112
  • 140
Mohsen
  • 64,437
  • 34
  • 159
  • 186

2 Answers2

58

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

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 12
    You should get in the habit of using single quotes all the time, _except_ when you actually need expansion inside the quotes. – Barmar Nov 11 '13 at 20:24
  • It's cool, but is not helps me. I use single quotes, but the some command prompt ("> ") appears after I type "enter". – James Bond Sep 30 '20 at 10:42
  • 4
    That will happen if you have unbalanced quotes. – Barmar Sep 30 '20 at 13:38
-1

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/.

Akanksha
  • 11
  • 3