Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of apostrophe (single-quote) in a Git commit message via command line [duplicate]

Tags:

git

bash

escaping

I am trying to take this one step further. How could this work in a standard Bash shell?

git commit -m 'cracked enigma's code' 

Could this simply be done with backslash-escaping like the following?

git commit -m 'cracked enigma\'s code' 

Further, how could double-quotes be used? Also by backslash-escaping? Would that be the best way? Are there any good alternative ways?

git commit -m 'cracked the "real" enigma's code' 
like image 244
nutty about natty Avatar asked Apr 16 '13 09:04

nutty about natty


People also ask

How do I escape a single quote in CMD?

It's done by finishing already opened one ( ' ), placing escaped one ( \' ), then opening another one ( ' ). This syntax works for all commands.

What does '- M in commit mean?

The -m OptionThe message should be a short description of the changes being committed. The message should be at the end of the command and it must be wrapped in quotations " " . An example of how to use the -m option: git commit -m "My message"

How do you reword a commit message?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.

How do I write a multiline commit message?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.

How do I run git commit without a message?

Run git commit without a message or option and it'll open up your default text editor to write a commit message. To configure your "default" editor: git config --global core.editor nano This would configure Git to use nano as your default editor.

How to create and practice git commit message using two Repos?

Wrap each line in the body after 72 characters. If your commit message has a body, separate the body and the subject line using a blank line. Enough with rules. Let's do some practice. We will configure the default editor before creating and practicing git commit message using two repos.

What is a GitHub commit message and why is it important?

Git commit message is crucial in the git workflow as it determines the cleanliness of the history. Here is how it relates to the workflow. notifies git to create a repository in your current directory. It does that by creating a subdirectory called .git. that stores all information about the repository.

How can I tell if a git commit was taken into account?

When leaving the editor and creating your Git commit message, you will be able to see that the short message was taken into account to create the commit. Similarly, if you try to inspect your Git history, you will be able to see that only the short message is visible to other users.


2 Answers

Use double quotes:

git commit -m "cracked enigma's code" 

Or, if your message contains other special characters, use double quotes or backslash only for the single quote:

git commit -m 'cracked $enigma'"'"'s code' git commit -m 'cracked $enigma'\''s code' 
like image 161
choroba Avatar answered Sep 21 '22 21:09

choroba


There is no need to escape the ' character if your commit is double quoted.

git commit -m "cracked enigma's code" 

EDIT: Anyway, when you have some special characters to add in the commit message I prefer to edit in a editor (like nano or vim), commiting without the -m option.

git commit 

And then put the message and exit. It's more confortable instead of thinking how you have to escape all those quotes and double quotes.

like image 21
Pigueiras Avatar answered Sep 20 '22 21:09

Pigueiras