12

I was really happy I fixed this stupid bug in my rails code and I happily typed the following into terminal:

git add .
git commit -am "Finally fixed that difficult bug!"

Only to find out that git doesn't like "!". Does anyone know of a way I can get it into my commit message?

Mwiza
  • 7,780
  • 3
  • 46
  • 42
hwrdprkns
  • 7,525
  • 12
  • 48
  • 69
  • Assuming you're not creating a new file, you don't need both a "git add" and a "commit -a" – Robert Dec 16 '10 at 02:44
  • I'm not certain that Git appreciated `f*cking` either :-) – Tim Biegeleisen May 26 '16 at 02:36
  • Possible duplicate of [How to escape single quotes within single quoted strings?](https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings) – Kcvin Aug 01 '17 at 15:28
  • I voted that way because although they aren't exact Q's, this question was closed as well: https://stackoverflow.com/questions/16033158/use-of-apostrophe-single-quote-in-a-git-commit-message-via-command-line – Kcvin Aug 01 '17 at 15:29

2 Answers2

29

Use single quotes. I don't know why it doesn't work in double quotes. It's actually a problem with your shell rather than git, in bash it has to do with command history.

You can also leave out the 'm' option and enter your commit message in your editor. That way you don't ever have to worry about escaping.

Paige Ruten
  • 172,675
  • 36
  • 177
  • 197
  • 3
    Double quotes allow most expansions. The purpose is to group into a single argument. – Matthew Flaschen Dec 16 '10 at 02:50
  • When I used single quotes I was able to use the exclamation point. I don't think its possible with a single line, but this definitely answers the question. – hwrdprkns Dec 17 '10 at 19:49
13

! is the "History expansion" character in Bash, and it is the shell that is causing this character to foul up.

See section: http://www.gnu.org/software/bash/manual/bashref.html#Quoting

Subsection: http://www.gnu.org/software/bash/manual/bashref.html#Double-Quotes

(Use a \! )

Adam Vandenberg
  • 19,991
  • 9
  • 54
  • 56