Use of an exclamation mark in a Git commit message via the command line Use of an exclamation mark in a Git commit message via the command line bash bash

Use of an exclamation mark in a Git commit message via the command line


Use single quotes instead of double quotes

git commit -am 'Nailed it!'

Alternatively, if you need to use double quotes for whatever reason but still want a literal ! then turn off history expansion at the top of your script via set +H


Another way to solve that is to add a space after ! like:

git commit -am "Nailed it! "

Note the space between ! and the last ".

(The space won't be included in the commit message - Git trims trailing whitespace from commit messages automatically.)


No need to remember what quotes or escapes to use, instead

  1. Type your command (or part of it)
  2. In your command line, pressCtr X E » will open your "external editor".
  3. Edit your command, and close your editor.

… the command will be executed &any special characters will show up correctly in the Git commit message!

(NB many other uses: typing complex commands, adding line breaks in your commit message etc.)