如何获得最近提交的Git分支列表?

Joe*_*ite 1197 git version-control branch

我想得到一个Git存储库中所有分支的列表,顶部有"最新鲜"的分支,其中"最新鲜"的分支是最近提交的分支(因此,更可能是一个分支)我想要注意).

有没有办法可以使用Git(a)通过最新提交对分支列表进行排序,或者(b)以某种机器可读格式获取分支列表以及每个分支的最后提交日期?

最糟糕的情况是,我总是可以运行git branch以获取所有分支的列表,解析其输出,然后git log -n 1 branchname --format=format:%ci为每个分支获取每个分支的提交日期.但这将在Windows机器上运行,其中启动一个新进程相对昂贵,因此如果有很多分支,每个分支启动Git可执行文件可能会变慢.有没有办法用一个命令完成所有这些?

Jak*_*ski 1692

使用--sort=-committerdate选项git for-each-ref;

也可从Git的2.7.0git branch:

基本用法:

git for-each-ref --sort=-committerdate refs/heads/

# Or using git branch (since version 2.7.0)
git branch --sort=-committerdate  # DESC
git branch --sort=committerdate  # ASC
Run Code Online (Sandbox Code Playgroud)

结果:

结果

高级用法:

git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
Run Code Online (Sandbox Code Playgroud)

结果:

结果

  • 这是一个彩色版本,包括哈希,消息,基于提交日期的升序排序,以及每个分支上最后一次提交的相对年龄.我从上面偷走了你们的所有想法.它位于`[alias]`部分的.gitconfig中,我喜欢它.`br = for-each-ref --sort = committerdate refs/heads/--format ='%(HEAD)%(颜色:黄色)%(refname:short)%(颜色:重置) - %(颜色:红色) )%(objectname:short)%(color:reset) - %(内容:subject) - %(authorname)(%(颜色:绿色)%(committerdate:relative)%(color:reset))'` (71认同)
  • @ilius:正如@BeauSmith写道:`git for-each-ref --sort = -committerdate --format ='%(refname:short)'refs/heads /`.git-for-each-ref(1)联机帮助页说:*对于ref的非模糊短名称,附加`:short`.* (36认同)
  • 这对我来说更好:`git for-each -ref -sort = -committerdate refs/heads/--format ='%(refname)%(committerdate)%(authorname)'| sed's/refs\/ heads\/// g'` (35认同)
  • 完善!我甚至可以通过附加`--format =%(refname)`将输出限制为ref名称. (14认同)
  • @ilius:为什么不使用`:shortname`? (2认同)
  • 此外,从 Git 1.7.0 开始,您不再需要求助于管道(低级)命令;感谢GSoC项目的branch/tag/for-each-ref代码统一,您可以简单地使用`gitbranch--sort=-committerdate`。 (2认同)
  • @MikePercy ......什么呃......你在你的`.gitconfig[alias]`中还有什么?:) (2认同)
  • @KevinFriedheim主要只是这个和git日志着色的东西,但是如果您真的想知道:https://github.com/mpercy/Dotfiles/blob/master/gitconfig :) (2认同)
  • Jakub 的“高级用法”示例是升序类型,对于那些更喜欢“降序用法”的人,不要忽视他在简单示例中指出的细微差别(“-”符号)。这是:`git for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - % (color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' `.作为超级小编辑更有意义,以显示两个“高级用法”版本作为对答案的编辑,但我的小编辑被拒绝。 (2认同)

Bea*_*ith 118

git分支名称列表,按最近提交的顺序排序...

扩展Jakub的答案和Joe的提示,以下将删除"refs/heads /",因此输出只显示分支名称:


命令:

git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
Run Code Online (Sandbox Code Playgroud)

结果:

最近的git分支

  • aah - @jakub.g已经解释过:你可以通过refs/remotes /而不是refs/heads /来获得远程分支.完善!! (9认同)
  • 你也可以使用`--format =%(refname:short)`而不是依赖`cut`. (4认同)
  • 有没有办法为REMOTE存储库执行此操作? (3认同)
  • 现在你可以用 `git branch` 来做到这一点,所以获取本地、远程或所有分支的工作方式就像在 git-branch 上一样(即 -r、-a)。`git branch -r --sort=committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short) %(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'` (3认同)

nik*_*lay 86

这是最佳代码,它结合了另外两个答案:

git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
Run Code Online (Sandbox Code Playgroud)

  • 即使是一个小优化得到表格输出:`git for-each-ref --sort = -committerdate refs/heads/--format ='%(committerdate:short)%(authorname)%(refname:short)' ` (10认同)
  • 由于某种原因,我不得不在Windows上使用双引号,但否则这些就可以了:) (2认同)

use*_*406 78

这是一个简单的命令,列出了最新提交的所有分支:

git branch -v
Run Code Online (Sandbox Code Playgroud)

要按最近提交的顺序排序,请使用

git branch -v --sort=committerdate
Run Code Online (Sandbox Code Playgroud)

来源:http://git-scm.com/book/en/Git-Branching-Branch-Management

  • 根据问题,这不按提交日期排序. (34认同)
  • `git branch -av`如果你想看到非本地分支. (11认同)
  • `git Branch -v --format='%(committerdate:short) %(refname:short)'` 将包含日期。 (7认同)
  • 让 `git branch -v` 包含列出的每个提交的日期是否容易? (3认同)
  • 这太棒了。我喜欢`git branch -va --sort = -committerdate`来显示非本地分支,最近更改的分支在顶部。 (2认同)

dim*_*mid 54

我使用以下别名:

recent = "!r(){git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)'|column -ts'|'}; r"

产生: 结果

编辑:使用'|' 分开,感谢@BjörnLindqvist

更新:在当前分支之前添加*,感谢@elhadi
编辑:修复了当前分支是另一个分支的子字符串的情况

编辑:使用更简单的语法为当前分支,感谢@Joshua Skrzypek

  • 我必须添加--color = always以获得颜色。`git for-each-ref --sort = -committerdate refs / heads --format ='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative )|%(color:blue)%(subject)|%(color:洋红色)%(authorname)%(color:reset)'--color = always | column -ts'|'}` (7认同)
  • @mwfearnley:对我来说,在大括号内添加分号有助于 `!r(){git for-each-ref ... ;}; r` (4认同)
  • 伟大的别名!如果逗号字符可以出现在您的语言环境中的相对时间戳内,我会建议`column -ts'|'` 和管道字符。 (3认同)
  • 我无法将其用作git别名。我不得不使用`[alias]最近=!git for-each-ref --sort = -committerdate参考/头--format ='%(HEAD)%(color:yellow)%(refname:short)|%(颜色:粗绿色)%(提交日期:相对)|%(颜色:蓝色)%(主题)|%(颜色:洋红色)%(作者名)%(颜色:重置)'|列-ts'|'` (3认同)
  • 至少在最新版本的git中,您可以在格式字符串的开头添加`'%(HEAD)...'`以获得相同的效果,而无需通过`sed`命令 (2认同)
  • 我还需要在 `-ts'|'` 之后添加一个分号,即 `"!r(){ git ... -ts'|'; }; r"` (2认同)

est*_*ani 37

我还需要颜色,标签和远程参考,没有任何重复:

for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '! a[$0]++'
Run Code Online (Sandbox Code Playgroud)

因为引用可能很难,这里是bash的别名:

alias glist='for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '"'! a["'$0'"]++'"
Run Code Online (Sandbox Code Playgroud)


And*_*ndy 36

我能够参考上面的例子来创造最适合我的东西.

git for-each-ref --sort = -committerdate refs/heads/--format ='%(authordate:short)%(color:red)%(objectname:short)%(color:yellow)%(refname:short )%(颜色:重置)(%(颜色:绿色)%(committerdate:relative)%(颜色:重置))'

输出截图

  • 这个干净整洁。有时我会添加远程和作者名,如下所示: `git for-each-ref --sort=-committerdate refs/heads/ refs/remotes --format='%(authordate:short) %(authorname) %(color:红色)%(对象名称:短)%(颜色:黄色)%(参考名称:短)%(颜色:重置)(%(颜色:绿色)%(提交日期:相对)%(颜色:重置))'` (8认同)
  • 对我来说,这个开箱即用,与其他一些不同,所以我投了赞成票. (2认同)
  • 工作得非常好!谢谢!:-) (2认同)

unk*_*ror 26

仅获取根据提交者日期排序的前五个分支名称:

git branch --sort=-committerdate | head -5


pal*_*dot 25

我发现以下命令对我的目的很有帮助。

git branch --sort=-committerdate | head -n 10
Run Code Online (Sandbox Code Playgroud)

这将列出最新的 10 个分支。它很短,也可以在没有别名的情况下使用。


Joh*_*lor 24

其他答案似乎不允许传递-vv以获得详细输出.

所以这是一个git branch -vv按提交日期排序,保留颜色等的单行程序:

git branch -vv --color=always | while read; do echo -e $(git log -1 --format=%ct $(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') 2> /dev/null || git log -1 --format=%ct)"\t$REPLY"; done | sort -r | cut -f 2
Run Code Online (Sandbox Code Playgroud)

如果您还想打印提交日期,则可以使用此版本:

git branch -vv --color=always | while read; do echo -e $(git log -1 --format=%ci $(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') 2> /dev/null || git log -1 --format=%ci)" $REPLY"; done | sort -r | cut -d ' ' -f -1,4-
Run Code Online (Sandbox Code Playgroud)

样本输出:

2013-09-15   master                  da39a3e [origin/master: behind 7] Some patch
2013-09-11 * (detached from 3eba4b8) 3eba4b8 Some other patch
2013-09-09   my-feature              e5e6b4b [master: ahead 2, behind 25] WIP
Run Code Online (Sandbox Code Playgroud)

它可能更具可读性,分为多行:

git branch -vv --color=always | while read; do
    # The underscore is because the active branch is preceded by a '*', and
    # for awk I need the columns to line up. The perl call is to strip out
    # ansi colors; if you don't pass --color=always above you can skip this
    local branch=$(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g')
    # git log fails when you pass a detached head as a branch name.
    # Hide the error and get the date of the current head.
    local branch_modified=$(git log -1 --format=%ci "$branch" 2> /dev/null || git log -1 --format=%ci)
    echo -e "$branch_modified $REPLY"
# cut strips the time and timezone columns, leaving only the date
done | sort -r | cut -d ' ' -f -1,4-
Run Code Online (Sandbox Code Playgroud)

这也应该与其他参数一起使用git branch,例如-vvr列出远程跟踪分支,或-vva列出远程跟踪和本地分支.

  • 这是最好的.并且添加-avv也会考虑远程分支.谢谢你! (2认同)

Von*_*onC 22

git 2.7(2015年第4季度)将直接引入分支排序git branch:
请参阅提交aa3bc55,提交aedcb7d,提交1511b22,提交f65f139,...(2015年9月23日),提交aedcb7d,提交1511b22,提交ca41799(2015年9月24日),以及提交f65f139,...(2015年9月23日)作者:Karthik Nayak(KarthikNayak).
(由Junio C gitsterHamano合并- -提交7f11b48,2015年10月15日)

特别是,提交aedcb7d:

branch.c:使用' ref-filter'API

制作" branch.c"使用" ref-filter"的API,通过裁判排序迭代.这删除了' branch.c'用ref-filter'库'调用替换它时使用的大部分代码.

添加了选项--sort=<key>:

根据给定的密钥排序.
前缀-按值的降序排序.

您可以--sort=<key>多次使用该选项,在这种情况下,最后一个键成为主键.

支持的密钥与中git for-each-ref的密钥相同.
排序顺序默认为基于完整引用名称(包括refs/...前缀)的排序.这首先列出分离的HEAD(如果存在),然后是本地分支,最后是远程跟踪分支.

这里:

git branch --sort=-committerdate 
Run Code Online (Sandbox Code Playgroud)

或者(见下面的Git 2.19)

# if you are sure to /always/ want to see branches ordered by commits:
git config --global branch.sort -committerdate
git branch
Run Code Online (Sandbox Code Playgroud)

另见Karthik Nayak()提交9e46833(2015年10月30日). 帮助:Junio C Hamano().(通过合并JUNIOÇ滨野- -提交415095f,03 2015年11月)KarthikNayak
gitster
gitster

当按照数值(例如--sort=objectsize)进行排序时,当两个ref保持相同的值时,没有回退比较.如Johannes Sixt($ gmane/280117)所指出的,这可能会导致意外的结果(即无法预先确定具有相同值的列表引用的顺序).

因此,只要其他标准相等,就根据refname回退到字母比较.

$ git branch --sort=objectsize

*  (HEAD detached from fromtag)
      branch-two
      branch-one
      master
Run Code Online (Sandbox Code Playgroud)

使用Git 2.19,可以默认设置排序顺序.
git branch支持配置branch.sort,比如git tag已有配置tag.sort.
Samuel Maftoul 提交的560ae1c(2018年8月16日)(``).
(由Junio C gitsterHamano合并- -提交d89db6f,2018年8月27日)

branch.sort:
Run Code Online (Sandbox Code Playgroud)

此变量控制显示时分支的排序顺序git-branch.
如果未--sort=<value>提供" "选项,则此变量的值将用作默认值.


要列出远程分支,请使用git branch -r --sort=objectsize.该-r标志使其列出远程分支而不是本地分支.


n8t*_*8tr 19

我喜欢使用相对日期并缩短分支名称,如下所示:

git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
Run Code Online (Sandbox Code Playgroud)

哪个给你输出:

21 minutes ago  nathan/a_recent_branch
6 hours ago     master
27 hours ago    nathan/some_other_branch
29 hours ago    branch_c
6 days ago      branch_d
Run Code Online (Sandbox Code Playgroud)

我建议制作一个bash文件,用于添加所有您喜欢的别名,然后将脚本分享给您的团队.这是一个添加这个的例子:

#!/bin/sh

git config --global alias.branches "!echo ' ------------------------------------------------------------' && git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads && echo ' ------------------------------------------------------------'"
Run Code Online (Sandbox Code Playgroud)

然后你可以这样做以获得一个格式良好和排序的本地分支列表:

git branches
Run Code Online (Sandbox Code Playgroud)

更新:如果您想要着色,请执行此操作:

#!/bin/sh
#
(echo ' ------------------------------------------------------------??' && git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads && echo ' ------------------------------------------------------------??') | grep --color -E "$(git rev-parse --abbrev-ref HEAD)$|$"
Run Code Online (Sandbox Code Playgroud)

  • 花哨的彩色输出很花哨,但这很简单,正是我所寻找的。将“refs/heads”替换为“refs/remotes”以查看远程分支。 (2认同)

use*_*247 14

从git 2.19开始,您可以简单地:

git branch --sort=-committerdate
Run Code Online (Sandbox Code Playgroud)

你也可以:

git config branch.sort -committerdate
Run Code Online (Sandbox Code Playgroud)

因此,无论何时在当前存储库中列出分支,它都将按committerdate排序.

如果每次列出分支时,都希望它们按comitterdate排序:

git config --global branch.sort -committerdate
Run Code Online (Sandbox Code Playgroud)

免责声明:我是git中这个功能的作者,我在看到这个问题时实现了它.

  • 最新的答案,比使用复杂的脚本或别名要容易得多 (2认同)

epy*_*nkn 11

添加一些颜色(因为pretty-format不可用)

[alias]
    branchdate = for-each-ref --sort=-committerdate refs/heads/ --format="%(authordate:short)%09%(objectname:short)%09%1B[0;33m%(refname:short)%1B[m%09"
Run Code Online (Sandbox Code Playgroud)


hIp*_*pPy 10

Git v2.19引入了branch.sort配置选项(请参阅branch.sort)。

因此git branch默认情况下将按提交者日期(降序)排序

# gitconfig
[branch]
    sort = -committerdate     # Descending
Run Code Online (Sandbox Code Playgroud)

脚本:

git config --global branch.sort -committerdate
Run Code Online (Sandbox Code Playgroud)

所以,

git branch
Run Code Online (Sandbox Code Playgroud)

输出:

* dev
  master
  _
Run Code Online (Sandbox Code Playgroud)

git branch -v
Run Code Online (Sandbox Code Playgroud)

输出:

* dev    0afecf5 Merge branch 'oc' into dev
  master 652428a Merge branch 'dev'
  _      7159cf9 Merge branch 'bashrc' into dev
Run Code Online (Sandbox Code Playgroud)


Ron*_*era 8

我有同样的问题,所以我写了一个名为Twig的Ruby gem .它按时间顺序列出分支(最新的第一个),并且还可以让您设置最大年龄,以便您不列出所有分支(如果您有很多分支).例如:

$ twig

                              issue  status       todo            branch
                              -----  ------       ----            ------
2013-01-26 18:00:21 (7m ago)  486    In progress  Rebase          optimize-all-the-things
2013-01-26 16:49:21 (2h ago)  268    In progress  -               whitespace-all-the-things
2013-01-23 18:35:21 (3d ago)  159    Shipped      Test in prod  * refactor-all-the-things
2013-01-22 17:12:09 (4d ago)  -      -            -               development
2013-01-20 19:45:42 (6d ago)  -      -            -               master
Run Code Online (Sandbox Code Playgroud)

它还允许您存储每个分支的自定义属性,例如,票证ID,状态,待办事项,并根据这些属性过滤分支列表.更多信息:http://rondevera.github.io/twig/

  • 这个名字可能没什么用,因为我很确定那里有几个同名的软件. (5认同)

bde*_*ham 8

我想出了以下命令(适用于Git 2.13及更高版本):

git branch -r --sort=creatordate \
    --format "%(creatordate:relative);%(committername);%(refname:lstrip=-1)" \
    | grep -v ";HEAD$" \
    | column -s ";" -t
Run Code Online (Sandbox Code Playgroud)

如果没有column,可以用最后一行替换

    | sed -e "s/;/\t/g"
Run Code Online (Sandbox Code Playgroud)

输出看起来像

6 years ago             Tom Preston-Werner  book
4 years, 4 months ago   Parker Moore        0.12.1-release
4 years ago             Matt Rogers         1.0-branch
3 years, 11 months ago  Matt Rogers         1.2_branch
3 years, 1 month ago    Parker Moore        v1-stable
12 months ago           Ben Balter          pages-as-documents
10 months ago           Jordon Bedwell      make-jekyll-parallel
6 months ago            Pat Hawks           to_integer
5 months ago            Parker Moore        3.4-stable-backport-5920
4 months ago            Parker Moore        yajl-ruby-2-4-patch
4 weeks ago             Parker Moore        3.4-stable
3 weeks ago             Parker Moore        rouge-1-and-2
19 hours ago            jekyllbot           master
Run Code Online (Sandbox Code Playgroud)

我写了一篇关于各个部分如何运作的博客文章.


Jor*_*ugh 7

仅供参考,如果您想获得最近签出的分支列表(而不是最近提交的分支),您可以使用git的reflog:

$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | head -n5
master
stable
master
some-cool-feature
feature/improve-everything
Run Code Online (Sandbox Code Playgroud)

另请参阅:如何获取我最近检出的git分支列表?


joe*_*dle 5

这是另一个脚本,它执行所有其他脚本的操作。事实上,它为你的 shell 提供了一个函数。

它的贡献在于它从 Git 配置中提取一些颜色(或使用默认值)。

# Git Branch by Date
# Usage: gbd [ -r ]
gbd() {
    local reset_color=`tput sgr0`
    local subject_color=`tput setaf 4 ; tput bold`
    local author_color=`tput setaf 6`

    local target=refs/heads
    local branch_color=`git config --get-color color.branch.local white`

    if [ "$1" = -r ]
    then
        target=refs/remotes/origin
        branch_color=`git config --get-color color.branch.remote red`
    fi

    git for-each-ref --sort=committerdate $target --format="${branch_color}%(refname:short)${reset_color} ${subject_color}%(subject)${reset_color} ${author_color}- %(authorname) (%(committerdate:relative))${reset_color}"
}
Run Code Online (Sandbox Code Playgroud)


小智 5

这是我用来在最近的分支之间切换的一个小脚本:

#!/bin/bash
# sudo bash

re='^[0-9]+$'

if [[ "$1" =~ $re ]]; then
    lines="$1"
else
    lines=10
fi
branches="$(git recent | tail -n $lines | nl)"
branches_nf="$(git recent-nf | tail -n $lines | nl)"
echo "$branches"

# Prompt which server to connect to
max="$(echo "$branches" | wc -l)"
index=
while [[ ! ( "$index" =~ ^[0-9]+$ && "$index" -gt 0 && "$index" -le "$max" ) ]]; do
    echo -n "Checkout to: "
    read index
done

branch="$( echo "$branches_nf" | sed -n "${index}p" | awk '{ print $NF }' )"
git co $branch
clear
Run Code Online (Sandbox Code Playgroud)

使用这两个别名:

recent = for-each-ref --sort=committerdate refs/heads/ --format=' %(color:blue) %(authorname) %(color:yellow)%(refname:short)%(color:reset)'
recent-nf = for-each-ref --sort=committerdate refs/heads/ --format=' %(authorname) %(refname:short)'
Run Code Online (Sandbox Code Playgroud)

只需在 Git 存储库中调用它,它就会显示最后 N 个分支(默认为 10 个)以及每个分支旁边的数字。输入分支的编号,它会检查:

在此处输入图片说明


Vic*_*hoy 5

通常我们最近会考虑远程分支。所以试试这个

git fetch
git for-each-ref --sort=-committerdate refs/remotes/origin
Run Code Online (Sandbox Code Playgroud)


Zen*_*row 5

另一种变体:

git branch -r --sort=-committerdate --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts'|'
Run Code Online (Sandbox Code Playgroud)

值得注意的是,即使它正在查看远程分支中的更改,也值得在运行命令之前与 origin 同步(可以使用 git fetch),因为我发现如果您的本地 Git 文件夹尚未更新,它可能会返回过时的信息一会儿。

此外,这是一个适用于 Windows cmd 和 PowerShell 的版本(没有在列中显示输出,有兴趣看看是否有人可以使用):

git branch -r --sort=-committerdate --format="%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)" --color=always
Run Code Online (Sandbox Code Playgroud)