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

依然范特西╮ 提交于 2019-12-03 06:11:42

问题


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'

回答1:


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'



回答2:


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.



来源:https://stackoverflow.com/questions/16033158/use-of-apostrophe-single-quote-in-a-git-commit-message-via-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!