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?
When using a CLI, you might have situations where a branch or tag name contains special characters that have a special meaning for your shell environment. To use these characters safely in a Git command, they must be quoted or escaped, otherwise the command may have unintended effects.
Git is very permissive about what characters are allowed in branch and tag names. When using Git from a command-line shell, you may need to escape or quote special characters. Most repositories use simple branch names, such as main or update-icons. Tag names also usually follow a basic format, such as a version number like v1.2.3.
If you want to use a special character as a literal (non-special) character, you have to tell the Bash shell. This is called quoting, and there are three ways to do it. If you enclose the text in quotation marks (“…”), this prevents Bash from acting on most of the special characters, and they just print.
When using Git from a command-line shell, you may need to escape or quote special characters. Most repositories use simple branch names, such as main or update-icons. Tag names also usually follow a basic format, such as a version number like v1.2.3.
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.
! 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 \! )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With