受到这个关于十六进制颜色代码在git日志格式的回复的启发,我试着做同样的事情。当在终端中直接使用它时,它工作得很好:
$git log --format="%h%C(#ff69b4)%d%C(reset) %s"|head -1
dc814e3 (HEAD -> master, origin/master, origin/HEAD) Compilation help added
如果我在.gitconfig
的别名中添加log --format="%h%C(#ff69b4)%d%C(reset) %s"
部分,会出现问题:
[alias]
ll =log --format="%h%C(#ff69b4)%d%C(reset) %s"
给出错误:
$git ll
fatal: ambiguous argument '%s': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
一个搜索给出了解决这类问题的方法:建议用"
转义"
。
如果我这样做,例如
[alias]
ll =log --format="%h%C(#ff69b4)%d%C(reset) %s"
I get error:
git ll
fatal: Bad alias.ll string: unclosed quote
我正在使用:
$echo $TERM; echo $SHELL; git --version
xterm-256color
/bin/bash
git version 2.4.3
我在这里做错了什么?
要完成Roman的回答,问题实际上在于别名需要正确地用引号括起来:
我们有什么:
ll =log --format="%h%C(#ff69b4)%d%C(reset) %s"
我们需要什么:
ll ="log --format="%h%C(#ff69b4)%d%C(reset) %s""
^ ^
避免手工编辑.gitconfig
,直接使用
git config --global alias.ll 'log --format="%h%C(#ff69b4)%d%C(reset) %s"'
我也是这样。
git log --format="%h%C(#ff69b4)%d%C(reset) %s"
但不在.gitconfig
在.gitconfig文件中,我把这个简单的引号,对我来说很好:
git log --format='"%h%C(#ff69b4)%d%C(reset) %s"'
在我看来,这种行为将根据您的系统而改变。您必须在您的系统上进行试验以获得正确的组合。