简体   繁体   English

高级git日志-不同提交者的不同颜色

[英]Advanced git log - Different colors for different committers

I currently have this alias set up on my Windows machine: ("lastcd" = "LastCommitterDate") 我目前在Windows计算机上设置了此别名:(“ lastcd” =“ LastCommitterDate”)

[alias] [别名]

lastcd = "!f() { git log -$1 --pretty=format:'%C(yellow)%h%C(reset) - %s %C(red)(%cn)%C(reset) %C(green)(%cr)%C(reset)'; }; f" lastcd =“!f(){git log-$ 1 --pretty = format:'%C(黄色)%h%C(重置)-%s%C(红色)(%cn)%C(重置)%C (绿色)(%cr)%C(重置)';}; f“

And the output would be as expected. 和输出将是预期的。 But all committers names are displayed in red. 但是所有提交者名称都显示为红色。 Is it possible to display other committers as red and my own commits as a different color?? 是否可以将其他提交者显示为红色,而我自己的提交显示为其他颜色?

If the answer is "just do a script" 如果答案是“只是编写脚本”

I must disappoint you.. I have little experience with the whole script.. Unix.. thingy.. Born and raised in windows. 我必须让您失望。.我对整个脚本没有什么经验。.Unix ..有点..在Windows中出生和提出的。 I have tried setting up scripts for git but I could only get them to work inside the "C:\\users\\me.bashrc" file. 我尝试为git设置脚本,但只能在“ C:\\ users \\ me.bashrc”文件中使用它们。 And dumping a bunch of different copy-paste scripts in there seems like a bad practice..? 并且在其中转储一堆不同的复制粘贴脚本似乎是个坏习惯。

If someone could give me a walk through of the set up process for a "hello world" script that would work in git bash I would be a very happy man! 如果有人能让我逐步了解可以在git bash中运行的“ hello world”脚本的设置过程,我将是一个非常高兴的人!

Best regards Edvin 最好的问候埃德文

Not sure there is a way to colorize username only using git, so you might try the following: 不确定是否有一种仅使用git为用户名着色的方法,因此您可以尝试以下操作:

git log --pretty=format:"%C(yellow)%h%C(reset) - %s %C(red)(%cn)%C(reset) %C(green)(%cr)%C(reset)" | sed "s/\(($(git config --get user.name)\)/$(tput setaf 4)\1/"  | less -R

The sed command finds and adds a blue color ( $(tput setaf 4) ) to your git user name ( $(git config --get user.name) ) . sed命令查找并向您的git用户名( $(git config --get user.name) )添加蓝色( $(tput setaf 4) $(git config --get user.name) )。

less -R emulates the git log behavior showing all colors. less -R模拟显示所有颜色的git log行为。

This works using bash on the OS I was born and raised ;-) 这在我出生和成长的操作系统上使用bash起作用;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM