如何使用图形在git日志中进行对齐 [英] How to do alignment in git logs with graph

查看:124
本文介绍了如何使用图形在git日志中进行对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git log --abbrev-commit --pretty=format:'%h %<(72,trunc)%s %d'之类的东西,您可以获得带有图形的对齐良好的git commit消息.如果删除--graph选项,则它完全对齐.该命令大致如下所示

With something like git log --abbrev-commit --pretty=format:'%h %<(72,trunc)%s %d', you can get a fairly well aligned git commit message with a graph. It is completely aligned if you drop the --graph option. Here is roughly what the command looks like

*   40f1481 Commit title message        (HEAD, dev)
|\                                                                     
| * 9b5122d Commit title message        (debug)
| * fe7ddfe Commit title message               
| * 8e4d414 Commit title message      
| * 53affdd Commit title message    
| * a45fbaf Commit title message             
|/                                                                     
* 36b23c3 Commit title message                     
* 5b7bfe1 Commit title message        (master)


问题在于,使用图形符号时,对齐方式混乱了,如您在前两次提交中所看到的.这是理想情况下的外观


The issue is that with the graph symbols the alignment is messed up, as you can see in the first two commits. Here is what it should ideally look like

*   40f1481 Commit title message        (HEAD, dev)
|\                                                                     
| * 9b5122d Commit title message        (debug)
| * fe7ddfe Commit title message               
| * 8e4d414 Commit title message      
| * 53affdd Commit title message    
| * a45fbaf Commit title message             
|/                                                                     
*   36b23c3 Commit title message                     
*   5b7bfe1 Commit title message        (master)

我的问题是,使用制图选项时,是否有用于获得正确对齐方式的选项?还是获取图形的宽度,以便您可以相应地填充日志?

My question is there an option for getting the correct alignment when using the graphing option? Or to get the width of the graph so that you can pad the log accordingly?

我知道一个快速的技巧是仅通过制表符(%x09)填充第一个选项,它可能适用于大多数项目,但是我想知道它们是否在美学上优越,万无一失.最小填充,但在5不够的情况下也可以使用.这是选项卡解决方案失败的示例

I know a quick hack would be to just pad the first option by tab (%x09), and it should work for probably most projects, but I'm wondering if their is a aesthetically superior, foolproof option that gets by with the minimum padding but also works in cases where 5 wouldn't be enough. Here is an example where the tab solution fails

使用列登录,不带彩色图形.

Log with using columns, without colored graph.

完全成功!稍后将尝试更新.

Complete success! Will try to update later.

推荐答案

我最近看到的git log正确对齐的位置是

The closest I have seen a git log properly aligned is in garybernhardt/dotfiles/.githelpers.

加里使用:

我在复制仓库git的克隆内部进行了测试:

vonc@VONCAVN7:~/gits/src/git$ 
git -c color.ui=auto log --graph --pretty=tformat:"%C(yellow)%h%Creset}%Cgreen(%ar)%Creset}%C(bold blue)<%an>%Creset}%C(bold red)%d%Creset %s" -100|  column -s '}' -t

多行:

git -c color.ui=auto log --graph \
  --pretty=tformat:"%C(yellow)%h%Creset}%Cgreen(%ar)%Creset}%C(bold blue)<%an>%Creset}%C(bold red)%d%Creset %s" \
  -100|  column -s '}' -t

但是:它只能在color.ui设置为false或auto的情况下使用,而不是始终设置:颜色会弄乱列的对齐方式.

BUT: it only works with color.ui set to false or auto, not set to always: colors will mess up the colum alignment.

没有颜色:

* 238e487ea                    (3 weeks ago)  <Junio C Hamano>         (HEAD -> master, tag: v2.14.1-b5, origin/master, origin/HEAD) The fifth batch post 2.14
*   6e6ba65a7                  (3 weeks ago)  <Junio C Hamano>         Merge branch 'mg/killed-merge'
|\
| * 9d89b3552                  (3 weeks ago)  <Michael J Gruber>       merge: save merge state earlier
| * 8e6a6bb36                  (3 weeks ago)  <Michael J Gruber>       merge: split write_merge_state in two
| * 62dc42b93                  (3 weeks ago)  <Michael J Gruber>       merge: clarify call chain
| * e2de82f27                  (4 weeks ago)  <Michael J Gruber>       Documentation/git-merge: explain --continue
* |   eabdcd4ab                (3 weeks ago)  <Junio C Hamano>         Merge branch 'jt/packmigrate'
|\ \
| * | 7709f468f                (4 weeks ago)  <Jonathan Tan>           pack: move for_each_packed_object()
| * | f9a8672a8                (4 weeks ago)  <Jonathan Tan>           pack: move has_pack_index()
...
...
...
| * | | | | | | | fdbdb64f4    (5 weeks ago)  <Jeff King>              interpret-trailers: add an option to show only existing trailers
| * | | | | | | | 56c493ed1    (5 weeks ago)  <Jeff King>              interpret-trailers: add an option to show only the trailers
| * | | | | | | | 8abc89800    (5 weeks ago)  <Jeff King>              trailer: put process_trailers() options into a struct
* | | | | | | | |   bfd91b413  (3 weeks ago)  <Junio C Hamano>         Merge branch 'pb/trailers-from-command-line'
|\ \ \ \ \ \ \ \ \
| * | | | | | | | | c88bf5436  (7 weeks ago)  <Paolo Bonzini>          interpret-trailers: fix documentation typo
| * | | | | | | | | 0ea5292e6  (7 weeks ago)  <Paolo Bonzini>          interpret-trailers: add options for actions

前100次提交完全对齐.

The first 100 commits are perfectly aligned.

有颜色...

在将git log输出传递到列之前,您需要对其进行其他预处理.
请参阅"漂亮的打印列中的颜色逃逸代码".

You would need additional pre-processing of the git log output before piping it to column.
See "Color escape codes in pretty printed columns".

这篇关于如何使用图形在git日志中进行对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆