无法在.gitconfig中添加--grep
我无法在gitconfig中使用grep命令创建别名。 添加以下行后,我开始在运行别名时出错无法在.gitconfig中添加--grep,git,Git,我无法在gitconfig中使用grep命令创建别名。 添加以下行后,我开始在运行别名时出错 log --grep="BUILD\|Public Changes" --invert-grep 基本上,我的目的是避免git提交消息列表中的构建和公共更改 编辑: 当从git cmdline运行时,此选项有效: git log --grep="BUILD\|Public Changes" --invert-grep 但这(在gitconfig中)给出了一个错误: ls = log --grep="
log --grep="BUILD\|Public Changes" --invert-grep
基本上,我的目的是避免git提交消息列表中的构建和公共更改
编辑:
当从git cmdline运行时,此选项有效:
git log --grep="BUILD\|Public Changes" --invert-grep
但这(在gitconfig中)给出了一个错误:
ls = log --grep="BUILD\|Public Changes" --invert-grep
错误(未在问题中列出)为
我首先通过从.git/config
中删除它,然后运行以下命令来修复此问题:
git config alias.ls 'log --grep="BUILD\|Public Changes" --invert-grep'
它生成的配置文件如下所示:
[alias]
ls = log --grep=\"BUILD\\|Public Changes\" --invert-grep
似乎引号和反斜杠都需要转义才能成为有效的语法
下面是正在运行的命令(GIT_TRACE=1
,您可以看到别名解析)
怎么了?
[alias]
ls = log --grep=\"BUILD\\|Public Changes\" --invert-grep
$ GIT_TRACE=1 git ls --format=%h
18:08:47.310940 git.c:561 trace: exec: 'git-ls' '--format=%h'
18:08:47.310989 run-command.c:334 trace: run_command: 'git-ls' '--format=%h'
18:08:47.311393 git.c:278 trace: alias expansion: ls => 'log' '--grep=BUILD|Public Changes' '--invert-grep'
18:08:47.311462 git.c:344 trace: built-in: git 'log' '--grep=BUILD|Public Changes' '--invert-grep' '--format=%h'
18:08:47.311680 run-command.c:334 trace: run_command: 'pager'
18:08:47.311856 run-command.c:193 trace: exec: 'pager'
a081dfd