34

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
  • 34,080
  • 14
  • 96
  • 122
Mohsen
  • 61,836
  • 32
  • 154
  • 180

2 Answers2

55

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
  • 669,327
  • 51
  • 454
  • 560
  • 11
    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
  • 2