相当于 oneline 的 Git 漂亮格式字符串,包括颜色

标签 git

我正在尝试将 oneline 的 Git 格式设置重新创建为格式字符串(以便进一步扩展)。

所以对于这个命令

git log --format=oneline

oneline 的格式字符串是什么? 我能得到的最接近的是

git log --format="%h %d %s"

但是,这不会产生任何颜色。我知道我可以对其中一些进行硬编码,比如提交哈希。但是 %d 具有动态颜色,具体取决于它显示的内容。

最佳答案

开启自动颜色

git log --format="%C(auto) %h %d %s"

输出看起来像这样

enter image description here

来自git log documentation

%C(…): color specification, as described in color.branch.* config option; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.

关于相当于 oneline 的 Git 漂亮格式字符串,包括颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30551818/

相关文章:

gitconfig : what characters to escape 中的 git 命令别名

python - 如果存在 .git 文件夹,则 pip install editable 在 Windows 中失败

git - xargs: git : 错误的文件编号

git - 什么时候应该使用 rm, git rm, git rm --cached, git add

git - 使用 git 发布到 node.js

linux - Git:使用可执行文件

git - 如何将本地分支恢复到 github 中的状态?

git - 我可以将另一个人的 repo 两次 fork 到我自己的帐户中吗?

git错误: fatal: unable to access 'https://dev.azure.com/****/' : Recv failure: Connection was reset while cloning

git - 在 GIT pull 期间忽略conf文件