我将此 npm 脚本添加到我的 package.json
文件中:
"gitlog" : "git log --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"
但是当我输入 npm run gitlog
时,我收到错误:fatal: Invalid object name '%H'.
我尝试将命令放入反引号中,但出现另一个错误。我必须对此命令进行一些转义,或者如何让它工作?
最佳答案
将所有单引号 ('
) 替换为 JSON 转义双引号 (\"
),例如
"gitlog": "git log --graph --decorate -30 --all --date-order --date=format:\"%Y-%m-%d %H:%M:%S\" --pretty=format:\"%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s\""
^^ ^^ ^^ ^^
关于git - 长 Git 命令会导致 npm 脚本出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63156451/