如何对齐 git 中的列以改进格式?

How to align columns in git to improve formatting?

我想改进 "git branch" 命令的格式,我在其中添加了包含 commit datecommit user[=23 的逻辑=].

git for-each-ref refs/heads/ --format='%(HEAD) %(color:bold yellow)%(refname:short)%(color:reset) %(color:green)%(committerdate)%(color:reset) - %(contents:subject) %(color:dim white) - %(authorname)%(color:reset)'

有没有办法改进从第一个(实际)输出到第二个(所需)输出的格式?

这根本不是一件紧急的事情,但很高兴。我玩过 git 格式,但我的知识有限。

我建议使用 %(align) 格式选项,如下所示:

%(align:width=<number of chars>) <column to align> %(end)

在你的例子中会给出

git for-each-ref refs/heads/ --format='%(HEAD) %(align:width=15)%(color:bold yellow)%(refname:short)%(end)%(color:reset) %(color:green)%(committerdate)%(color:reset) - %(contents:subject) %(color:dim white) - %(authorname)%(color:reset)'

尽管没有为对齐提供动态值,但它完成了工作,这很好,但可能不是必需的,具体取决于您的上下文。