无法使用CMD注册git`log`别名

问题描述 投票:0回答:1

我正在尝试使用 Windows CMD 为

log
命令添加别名(由于 Windows 使用
"
,请参阅 这个答案):

git log --pretty=format:"%C(yellow)%h %C(red)%ad %C(brightcyan)%d %C(white)%s" --date=format:"%Y-%m-%d %H:%M"

当我在 CMD 上执行该命令时,该命令工作正常,但是当我尝试将其另存为别名时,该命令不起作用:

> git config --system alias.time-log log --pretty=format:"%C(yellow)%h %C(red)%ad %C(brightcyan)%d %C(white)%s" --date=format:"%Y-%m-%d %H:%M"
usage: git config [<options>]
<bla bla bla...>

所以基本上发生了一些错误,它无法识别该命令。我尝试过使用别名更简单的命令:

> git config --system alias.time-log log --pretty=format:"%C(yellow)%h"
> git config --system alias.time-log log --pretty=format:'%C(yellow)%h'

但与我上面发布的答案中给出的解决方案相反,

log
之后的部分现在被截断。看看我何时查询我的别名列表:

> config --get-regexp ^alias\.
alias.time-log log
alias.time-log log

背景

几天前,我成功地为以下命令添加了别名,没有出现任何问题(我想我确实使用了双引号

"
):

git log --pretty=format:"%C(yellow)%h %C(red)%ad %C(brightcyan)%d %C(white)%s" --date=short

这就是我查询保存的别名时的显示方式:

> config --get-regexp ^alias\.
alias.date-log log --pretty=format:'%C(yellow)%h %C(red)%ad %C(brightcyan)%d %C(white)%s' --date=short
git logging cmd alias
1个回答
0
投票

由于您的命令由多个以空格分隔的选项组成,并且其中一些选项已经使用双引号,因此您确实需要将别名括在单引号内。

git config --system alias.time-log 'log --pretty=format:"%C(yellow)%h %C(red)%ad %C(brightcyan)%d %C(white)%s" --date=format:"%Y-%m-%d %H:%M"'

一般来说,当提供命令作为参数时,将其括在单引号内始终是一个好习惯。

© www.soinside.com 2019 - 2024. All rights reserved.