Joe*_*tra 6 git format git-branch
我想改进“gitbranch”命令的格式,我在其中添加了包含提交日期和提交用户的逻辑。
git for-each-ref refs/heads/ --format='%(HEAD) %(颜色:粗体黄色)%(refname:short)%(颜色:重置)%(颜色:绿色)%(committerdate)%(颜色:重置) - %(内容:主题) %(颜色:暗白色) - %(作者姓名)%(颜色:重置)'
是否有办法改进从第一个(实际)输出到第二个(所需)输出的格式?
这根本不是什么紧急的事情,但却是一件好事。我使用过 git 格式,但我的知识有限。
我建议使用%(align)格式选项,如下所示:
%(align:width=<number of chars>) <column to align> %(end)
Run Code Online (Sandbox Code Playgroud)
在你的例子中会给出
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)'
Run Code Online (Sandbox Code Playgroud)
它完成了这项工作,尽管没有为对齐提供动态值,这很好,但可能不是必需的,具体取决于您的上下文。