Pretty git branch graphs

前端 未结 30 1824
情话喂你
情话喂你 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 01:55

    GitGraph

    Generates a PNG or SVG representation of your Git repository's commit history.

    https://code.google.com/p/gitgraph

    0 讨论(0)
  • 2020-11-22 01:57

    Based on a Graphviz script I found in an answer to a related question, I've hacked up a ruby script that creates a summary view of a git repository. It elides all linear history and just shows "interesting" commits, i.e. those with multiple parents, multiple children, or pointed to by a branch or tag. Here's a snippet of the graph it generates for jquery:

    jquery sample

    git-big-picture and BranchMaster are similar tools that try to show only the high-level structure of a graph, by only displaying how tags, branches, merges, etc. are related.

    This question has some more options.

    0 讨论(0)
  • 2020-11-22 01:59

    Although sometimes I use gitg, always come back to command line:

    [alias]
        #quick look at all repo
        loggsa = log --color --date-order --graph --oneline --decorate --simplify-by-decoration --all
        #quick look at active branch (or refs pointed)
        loggs  = log --color --date-order --graph --oneline --decorate --simplify-by-decoration
        #extend look at all repo
        logga  = log --color --date-order --graph --oneline --decorate --all
        #extend look at active branch
        logg   = log --color --date-order --graph --oneline --decorate
        #Look with date
        logda  = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\" --all
        logd   = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\"        
        #Look with relative date
        logdra = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\" --all
        logdr = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\"  
    
        loga   = log --graph --color --decorate --all
    
        # For repos without subject body commits (vim repo, git-svn clones)
        logt  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\"
        logta  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all        
        logtsa = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all --simplify-by-decoration 
    

    As you can see is almost a keystroke saving aliases, based on:

    • --color: clear look
    • --graph: visualize parents
    • --date-order: most understandable look at repo
    • --decorate: who is who
    • --oneline: Many times all you need to know about a commit
    • --simplify-by-decoration: basic for a first look (just tags, relevant merges, branches)
    • --all: saving keystrokes with all alias with and without this option
    • --date=relative (%ar): Understand activity in repo (sometimes a branch is few commits near master but months ago from him)

    See in recent version of git (1.8.5 and above) you can benefit from %C(auto) in decorate placeholder %d

    From here all you need is a good understand of gitrevisions to filter whatever you need (something like master..develop, where --simplify-merges could help with long term branches)

    The power behind command line is the quickly config based on your needs (understand a repo isn't a unique key log configuration, so adding --numstat, or --raw, or --name-status is sometimes needed. Here git log and aliases are fast, powerful and (with time) the prettiest graph you can achieved. Even more, with output showed by default through a pager (say less) you can always search quickly inside results. Not convinced? You can always parse the result with projects like gitgraph

    0 讨论(0)
  • 2020-11-22 01:59

    some aliases in ~/.oh-my-zsh/plugins/git/git.plugin.zsh

    gke='\gitk --all $(git log -g --pretty=%h)'
    glg='git log --stat'
    glgg='git log --graph'
    glgga='git log --graph --decorate --all'
    glgm='git log --graph --max-count=10'
    glgp='git log --stat -p'
    glo='git log --oneline --decorate'
    glog='git log --oneline --decorate --graph'
    gloga='git log --oneline --decorate --graph --all'
    glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
    glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
    
    0 讨论(0)
  • 2020-11-22 01:59

    For OSX users, I've taken the @gospes example and slightly modified it for gsed (gnu-sed installed via homebrew) and adjusted the colors (to work with a black background, not sure how the original example could possibly render the way it does in the example since it specifies black text on a terminal with a black background).

    [alias]
        # tree, vtree, stree support
        logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(bold black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(bold black): %s%C(reset)'
        tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n         %C(bold black)[%cr]%C(reset)  %x09%C(bold black)%an: %s %C(reset)'
        stree = !bash -c '" \
        while IFS=+ read -r hash time branch message; do \
            timelength=$(echo \"$time\" | gsed -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);"' | less -r
        vtree = !bash -c '" \
        while IFS=+ read -r hash time branch message; do \
          timelength=$(echo \"$time\" | gsed -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);"' | less -r
    

    The key for OSX is to first install gnu sed (which has the -r option). Most easily done with homebrew, which will not overwrite the system-installed sed, but will instead install gnu sed as "gsed". Hope this helps @SlippD.Thompson who commented above about OSX not working.

    0 讨论(0)
  • 2020-11-22 02:00

    This is my take on this matter:

    Screenshot:

    Usage:

    git hist - Show the history of current branch

    git hist --all - Show the graph of all branches (including remotes)

    git hist master devel - Show the relationship between two or more branches

    git hist --branches - Show all local branches

    Add --topo-order to sort commits topologically, instead of by date (default in this alias)

    Benefits:

    • Looks just like plain --decorate, so with separate colors for different branch names
    • Adds committer email
    • Adds commit relative and absolute date
    • Sorts commits by date

    Setup:

    git config --global alias.hist "log --graph --date-order --date=short \
    --pretty=format:'%C(auto)%h%d %C(reset)%s %C(bold blue)%ce %C(reset)%C(green)%cr (%cd)'"
    
    0 讨论(0)
提交回复
热议问题