Git 记录所有,以不同方式显示当前提交
Git log all, display current commit differently
我倾向于经常使用 git log --all --graph --oneline
。
如果我的当前状态落后于上次提交,我很难在图形显示上找到我的位置。
有没有办法在保留一般显示(单行、图形)的情况下以某种方式突出显示当前修订?
您可以在提交列表中使用 --pretty
option of git log
to include the references(分支、标签和 HEAD
):
git log --all --graph --pretty='%C(green)%h%Creset %C(cyan)%d%Creset %s'
其中:
%C(color)
和 %Creset
分别更改输出颜色并将其重置为默认颜色
%h
扩展为缩写的提交散列
%d
扩展为指向提交的引用列表
%s
扩展到提交消息的第一行(即“summary”)
You can find the complete list of placeholders in the Pretty Formats section of the git log
documentation.
当然,您不会希望每次查看历史记录时都键入所有这些内容,所以让我们为它创建一个 alias:
git config --global alias.lg \
"log --all --graph --pretty='%C(green)%h%Creset %C(cyan)%d%Creset %s'"
此时你可以简单地说 git lg
。
或者,您可以在 format.pretty
配置设置:
git config --global format.pretty '%C(green)%h%Creset %C(cyan)%d%Creset %s'
我倾向于经常使用 git log --all --graph --oneline
。
如果我的当前状态落后于上次提交,我很难在图形显示上找到我的位置。
有没有办法在保留一般显示(单行、图形)的情况下以某种方式突出显示当前修订?
您可以在提交列表中使用 --pretty
option of git log
to include the references(分支、标签和 HEAD
):
git log --all --graph --pretty='%C(green)%h%Creset %C(cyan)%d%Creset %s'
其中:
%C(color)
和%Creset
分别更改输出颜色并将其重置为默认颜色%h
扩展为缩写的提交散列%d
扩展为指向提交的引用列表%s
扩展到提交消息的第一行(即“summary”)
You can find the complete list of placeholders in the Pretty Formats section of the
git log
documentation.
当然,您不会希望每次查看历史记录时都键入所有这些内容,所以让我们为它创建一个 alias:
git config --global alias.lg \
"log --all --graph --pretty='%C(green)%h%Creset %C(cyan)%d%Creset %s'"
此时你可以简单地说 git lg
。
或者,您可以在 format.pretty
配置设置:
git config --global format.pretty '%C(green)%h%Creset %C(cyan)%d%Creset %s'