Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do alignment in git logs with graph

Tags:

git

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?


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

enter image description here


Log with using columns, without colored graph.

enter image description here


Complete success! Will try to update later.

enter image description here

like image 454
Novice C Avatar asked Dec 24 '22 14:12

Novice C


1 Answers

Modern versions of Git (I have git 2.17.0 on cygwin environment) work fine with colorized graph and indentation without any additional tools or scripts.

My .gitconfig aliases part:

[alias]
    l   = log --graph --abbrev-commit --decorate=no --date=format:'%Y-%m-%d %H:%I:%S' --format=format:'%C(03)%>|(26)%h%C(reset)  %C(04)%ad%C(reset)  %C(green)%<(16,trunc)%an%C(reset)  %C(bold 1)%d%C(reset) %C(bold 0)%>|(1)%s%C(reset)' --all

I have tested it on django official repository and it works great:

like image 166
Murat Guchetl Avatar answered Dec 26 '22 09:12

Murat Guchetl