83

I am trying to take this one step further. How could this work in a standard Bash shell?

git commit -m 'cracked enigma's code'

Could this simply be done with backslash-escaping like the following?

git commit -m 'cracked enigma\'s code'

Further, how could double-quotes be used? Also by backslash-escaping? Would that be the best way? Are there any good alternative ways?

git commit -m 'cracked the "real" enigma's code'
4
  • 4
    "Could this simply be done with backslash escaping like so": You could just try yourself and find out! Commented Apr 16, 2013 at 9:19
  • 1
    @FelixKling true, but I'm a git-beginner and don't feel to courageous just yet. Commented Apr 16, 2013 at 9:23
  • 2
    This doesn't really have anything to do with courageousness. You can always create an empty git repository, create one file, create the commit and then see what the outcome is. The question itself is OK of course. Commented Apr 16, 2013 at 9:26
  • (for reference) gnu.org/software/bash/manual/bashref.html#Double-Quotes & gnu.org/software/bash/manual/bashref.html#Quoting Commented Apr 16, 2013 at 20:32

2 Answers 2

133

Use double quotes:

git commit -m "cracked enigma's code"

Or, if your message contains other special characters, use double quotes or backslash only for the single quote:

git commit -m 'cracked $enigma'"'"'s code'
git commit -m 'cracked $enigma'\''s code'
Sign up to request clarification or add additional context in comments.

5 Comments

what's the $-sign doing there? isn't that sth to define a variable? (sorry if this is too bash-basic...)
It's there to show why simple double quotes do not work. You can try with echo instead of git commit -m
Basically it’s because inside double quotes, variables are expanded; and $enigma would be a variable reference. So if you want your message to contain an actual dollar sign, you cannot use double quotes.
when trying to git commit with single quoted comments, one will get a "error: pathspec '_____' did not match any file(s) known to git."
Good answer. The concatenation ('"'"') is really the way to go. I use it all the time. It feels strange but works very well.
21

There is no need to escape the ' character if your commit is double quoted.

git commit -m "cracked enigma's code"

EDIT: Anyway, when you have some special characters to add in the commit message I prefer to edit in a editor (like nano or vim), commiting without the -m option.

git commit

And then put the message and exit. It's more confortable instead of thinking how you have to escape all those quotes and double quotes.

1 Comment

This is not true for git commit -m "pattern match wasn't exhaustive, scalac!" on OSX, git 2.15.1. Works if I leave out the exclamation. Weird stuff.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.