Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在git日志和gitconfig别名中使用十六进制颜色代码_Git - Fatal编程技术网

在git日志和gitconfig别名中使用十六进制颜色代码

在git日志和gitconfig别名中使用十六进制颜色代码,git,Git,受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(重置)%s”部分,就会出现

受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(重置)%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>...]'
我得到一个错误:

git ll
fatal: Bad alias.ll string: unclosed quote
我正在使用:

$echo $TERM; echo $SHELL; git --version
xterm-256color
/bin/bash
git version 2.4.3

我做错了什么?

避免手动编辑
.gitconfig
,只需使用

git config --global alias.ll 'log --format="%h%C(#ff69b4)%d%C(reset) %s"'
要完整回答,问题实际上在于别名需要正确地用引号括起来:

我们所拥有的:

ll =log --format=\"%h%C(#ff69b4)%d%C(reset) %s\"
我们需要:

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"'
在我看来,这种行为将根据您的系统而改变。
您必须进行试验,才能在系统上获得正确的组合。

请注意,如果您使用
闯入外壳,则可能需要转义,因为shell可能会将其解释为前一个命令参数的替换请求,其他特殊字符(如
$
或使用的附加引号)也是如此。
git log --format='"%h%C(#ff69b4)%d%C(reset) %s"'