.gitconfig [alias]无法识别字符串

时间:2014-08-22 18:40:00

标签: git alias git-config

我正在尝试为我的GIT创建一个类似的别名:

[alias]
    send = !git add . && git commit -m "AUTOCOMMIT: $(date)" && git push

此别名适用于不需要任何消息的微小修改。问题是每当我运行git send时,它都会返回以下内容:

$ git send
error: pathspec 'Fri' did not match any file(s) known to git.
error: pathspec 'Aug' did not match any file(s) known to git.
error: pathspec '22' did not match any file(s) known to git.
error: pathspec '11:31:18' did not match any file(s) known to git.
error: pathspec 'PDT' did not match any file(s) known to git.
error: pathspec '2014' did not match any file(s) known to git.

如果我手动运行该命令,则没有错误:

$ git add .
$ git commit -m "AUTOCOMMIT: $(date)"
[master] AUTOCOMMIT: Fri Aug 22 11:37:17 PDT 2014
 1 file changed, 1 deletion(-)
$ git push
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 368 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To <gitRepo>.git
   master -> master

有什么想法吗?

2 个答案:

答案 0 :(得分:5)

根据git-config(1)CONFIGURATION FILE: Syntax下:

  

字符串值可以完全或部分包含在double中   引号。如果您需要将变量值括在双引号中   想要保留前导或尾随空格,或者如果变量   值包含注释字符(即它包含#;)。双   引号"和变量值中的反斜杠\字符必须进行转义:   对\"使用"\\使用\

您不必严格添加第二组引号,因此:

[alias]
    send = !git add . && git commit -m \"AUTOCOMMIT: $(date)\" && git push

此外,如果使用git config保存别名,则可以避免手动转义:

$ git config --global \
    alias.send '!git add . && git commit -m "AUTOCOMMIT: $(date)" && git push'

答案 1 :(得分:0)

通过修改别名来解决它:

[alias]
    send = !git add . && git commit -m "\"AUTOCOMMIT: $(date)\"" && git push

问题仍然存在:为什么我需要逃避""?我期待整个字符串只能由shell执行。