Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special Character in Git possible?

Tags:

git

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?

like image 886
hwrdprkns Avatar asked Dec 16 '10 02:12

hwrdprkns


People also ask

How do I use special characters in a Git command?

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.

What characters are allowed in git branch and tag names?

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.

How do I use a non-special character in Bash?

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.

How do you name a git repository in command line?

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.


2 Answers

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.

like image 146
Paige Ruten Avatar answered Oct 04 '22 06:10

Paige Ruten


! 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 \! )

like image 42
Adam Vandenberg Avatar answered Oct 04 '22 04:10

Adam Vandenberg