23

Possible Duplicate:
How do I enter an exclamation point into a git commit message from the command line?

I'm new to git, and I did this command:

git commit -m "First Commit!"

This throws an error like this:

bash: !": event not found

Why is this error happening? Is is that in Git, I shouldn't use ! symbols in commit?

Are there other symbols which I shouldn't use or should escape with any escape sequence?

Paul R
  • 208,748
  • 37
  • 389
  • 560
Ant's
  • 13,545
  • 27
  • 98
  • 148

3 Answers3

41

Nothing to do with git, more to do with bash - escape the ! or use single quotes, i.e.

$ git commit -m "First Commit\!"

or, better:

$ git commit -m 'First Commit!'
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 14
    Escaping with a backslash as in your first method will leave an unsightly literal backslash in the actual commit message. The answer on [the post this is a dupe of](http://stackoverflow.com/questions/5131948/use-of-an-exclamation-mark-in-a-git-commit-message-via-command-line) is better. – 75th Trombone Dec 12 '12 at 21:24
  • 1
    FYI for someone who does not want to manually escape characters. Another approach is to use `git gui` command in terminal. then we can use the commit message without needing to manually escape the characters – firstpostcommenter Dec 23 '19 at 16:18
12

That's not git related at all, but bash related. Using ! in a string will cause bash to attempt history expansion. If you don't want that, either use single-quoted strings or escape the exclamation mark with a backslash.

Dominik Honnef
  • 17,937
  • 7
  • 41
  • 43
5

No, this is possible in with the git command line and double quotes. One easy fix is putting a space after !.

git commit -m "First Commit! "

Another way to get around this is by using git gui or just git commit and then specifying the message in the editor that opens.

The limitation is clearly a bash limitation and not a problem of git. You can avoid it using single quotes:

git commit -m 'First Commit!'
Unapiedra
  • 15,037
  • 12
  • 64
  • 93