git - 长 Git 命令会导致 npm 脚本出错

标签 git npm npm-scripts

我将此 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/

相关文章:

bash - 将 Bash 脚本中的命令选项与字符串分开

git - "single file"git 存储库格式?

node.js - 如何在 openshift 上安装全局 Node 模块?

node.js - 在reactApp创建中使用Webpack时出错-configuration.output.path : The provided value "./" is not an absolute path!“

node.js - eslint 不从 npm 脚本中的参数中获取文件名

linux - 在 Linux 上工作——如何从基础开始添加系统调用?

git - 如何从提交消息中获取提交哈希 (ID)

node.js - 除一个目录外的所有目录中的 npmignore .sh 文件

node.js - Node : how to avoid installing global packages

npm - 有什么方法可以使用不同的配置和 babel 生成多个转译文件吗?