Pretty git branch graphs

前端 未结 30 2020
情话喂你
情话喂你 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:14

    Built on top of TikZ & PGF, gitdags is a little LaTeX package that allows you to effortlessly produce vector-graphics commit graphs, and more.

    Automatic generation of an existing repository's commit graph is not the purpose of gitdags; the graphs it produces are only meant for educational purposes.

    I often use it to produce graphs for my answers to Git questions, as an alternative to ASCII commit graphs:

    • How can I do a bugfix on master and integrate it into my less stable branch(es)?
    • How does git commit --amend work, exactly?
    • Why does Git tell me "Not currently on any branch" after I run "git checkout origin/"?
    • What is the difference between merging master into branch and merging branch into master?
    • Git rebase --preserve-merges fails

    Here is an example of such a graph demonstrating the effects of a simple rebase:

    enter image description here

    \documentclass{article}
    
    \usepackage{subcaption}
    \usepackage{gitdags}
    
    \begin{document}
    
    \begin{figure}
      \begin{subfigure}[b]{\textwidth}
        \centering
        \begin{tikzpicture}
          % Commit DAG
          \gitDAG[grow right sep = 2em]{
            A -- B -- { 
              C,
              D -- E,
            }
          };
          % Tag reference
          \gittag
            [v0p1]       % node name
            {v0.1}       % node text
            {above=of A} % node placement
            {A}          % target
          % Remote branch
          \gitremotebranch
            [origmaster]    % node name
            {origin/master} % node text
            {above=of C}    % node placement
            {C}             % target
          % Branch
          \gitbranch
            {master}     % node name and text 
            {above=of E} % node placement
            {E}          % target
          % HEAD reference
          \gitHEAD
            {above=of master} % node placement
            {master}          % target
        \end{tikzpicture}
        \subcaption{Before\ldots}
      \end{subfigure}
    
      \begin{subfigure}[b]{\textwidth}
        \centering
        \begin{tikzpicture}
          \gitDAG[grow right sep = 2em]{
            A -- B -- { 
              C -- D' -- E',
              {[nodes=unreachable] D -- E },
            }
          };
          % Tag reference
          \gittag
            [v0p1]       % node name
            {v0.1}       % node text
            {above=of A} % node placement
            {A}          % target
          % Remote branch
          \gitremotebranch
            [origmaster]    % node name
            {origin/master} % node text
            {above=of C}    % node placement
            {C}             % target
          % Branch
          \gitbranch
            {master}      % node name and text 
            {above=of E'} % node placement
            {E'}          % target
          % HEAD reference
          \gitHEAD
            {above=of master} % node placement
            {master}          % target
        \end{tikzpicture}
        \subcaption{\ldots{} and after \texttt{git rebase origin/master}}
      \end{subfigure}
      \caption{Demonstrating a typical \texttt{rebase}}
    \end{figure}
    
    \end{document}
    

提交回复
热议问题