+2 votes
1 view
in DevOps and Agile by (30k points)

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?

2 Answers

0 votes
by (51.2k points)

For less number of branches we can use this command:

git log --graph --pretty=oneline

But in order to make the graph more pretty, you can do it in several ways

Generally, I have two aliases that I will throw in my ~/.gitignore file:

[alias]

lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

lg = !"git lg1"

After adding this to ~/.gitignore file the graphs are displayed on git log becomes prettier than earlier.

You can write your formats to make your branch graphs different.

Reference: https://git-scm.com/docs/git-log#Documentation/git-log.txt---graph

+1 vote
by (28.4k points)

Usage:

To show the history of the current branch

$ git hist 

To show the graph of all branches (including remotes)

$ git hist --all 

To show the relationship between two or more branches

$ git hist master devel 

To show all local branches

$ git hist --branches 

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

Benefits:

  • It looks just like plain --decorate, so with separate colors for different branch names
  • It adds committer email
  • It adds commit relative and absolute date
  • Also, it sorts commits by date 

Let us look at the setup:

$ git config --global alias.hist "log --graph --date-order --date=short \ --pretty=format:'%C(auto)%h%d %C(reset)%s %C(bold blue)Î %C(reset)%C(green)%cr (Í)'"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...