我对Linux比较新,所以这可能很简单但是当我在我的git提交消息周围使用引号(单引号或双引号)时,这些单词被视为文件名。如何在消息中使用-m和空格 - 我不想使用vi。
user@linux:~/Documents/tmp$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: afile
user@linux:~/Documents/tmp$ git commit -m ¨this message has spaces and fails¨
error: pathspec 'message' did not match any file(s) known to git.
error: pathspec 'has' did not match any file(s) known to git.
error: pathspec 'spaces' did not match any file(s) known to git.
error: pathspec 'and' did not match any file(s) known to git.
error: pathspec 'fails¨' did not match any file(s) known to git.
user@linux:~/Documents/tmp$ git commit -m ¨nospacesisokay¨
[master (root-commit) 37afcd6] ¨nospacesisokay¨
1 file changed, 1 insertion(+)
create mode 100644 afile
答案 0 :(得分:3)
使用常规引号(双引号"
或引号'
),同事:) ¨
对 bash 来说太奇特了所以它会拆分你的信息通过空格将标记分别传递给git
。
在类似unix的系统中,与MS Windows cmd.exe
不同,(嗯,MinGW和Cygwin也是类似unix :) :)将命令行拆分为令牌由shell执行,不管是{{1} } - 或sh
- 兼容的shell(bash,zsh,ash,sash,ksh,tcsh等等)。程序接收准备使用的参数数组。因此,如果用户想要传递带空格,转义序列等的行,她应该正确引用或转义该行。