Pretty git branch graphs

前端 未结 30 2042
情话喂你
情话喂你 2020-11-22 01:34

I\'ve seen some books and articles have some really pretty looking graphs of git branches and commits. How can I make high-quality printable images of git history?

30条回答
  •  时光取名叫无心
    2020-11-22 02:06

    I've added three custom commands: git tree, git stree and git vtree. I'll go over them in that order.

    [alias]
        tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n         %C(black)[%cr]%C(reset)  %x09%C(black)%an: %s %C(reset)'
    

    enter image description here

    With git stree and git vtree I've use bash to help with the formatting.

    [alias]
        logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
        stree = !bash -c '"                                                                             \
            while IFS=+ read -r hash time branch message; do                                            \
                timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
                timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
                printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\";          \
            done < <(git logx && echo);"'
    

    git_stree


    [alias]
        logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
        vtree = !bash -c '"                                                                             \
            while IFS=+ read -r hash time branch message; do                                            \
                timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
                timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
                printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\";  \
            done < <(git logx && echo);"'
    

    git_vtree


    EDIT: This works with git version 1.9a. The color value 'auto' is apparently making its debut in this release. It's a nice addition because branch names will get a different color. This makes it easier to distinguish between local and remote branches for instance.

提交回复
热议问题