Problem solve Get help with specific problems with your technologies, process and projects.

Examples of how to use the git log graph command

One of the coolest features of the git log command is the graphing feature. The git log graph command creates a graphic overview of how your various development pipelines have branched and merged over time. The fact that this visual display is done through a decidedly non-visual BASH shell or terminal window is what makes the feat particularly impressive.

The git log graph command

In its simplest form, the git log graph command looks as follows:

graph@log:~$ git log –graph

git log graph pretty

The git log graph command is too verbose without a pretty switch.

The problem with the basic –graph usage is that the verbosity of the log gets in the way.  Matching the git log graph command with a pretty oneline option makes the output look much nicer:

graph@log:~$ git log –graph pretty=online

You can condense this line by dropping the pretty switch:

graph@log:~$ git log –graph –online

Both of these options greatly improve the readablility of the git log graph, while at the same time allowing the creation and merging of branches over time to be displayed pleasantly.

Graph all git branches

To see all branches in the graph use the –all switch. Also, in most situations, the –decorate switch will provide all of the supplemental information you’ll need, all formatted and nicely color coded.

graph@log:~$ git log –all –decorate –oneline –graph

You can really get crazy with the way you format the git log, but these four switches together is all most Git users will ever need. The mnemonic a dog is a good way to remember this combo:

git log graph dog

The Git log graph a dog mnemonic.

graph@log:~$ git log --all --decorate --oneline --graph

A pretty git log graph

The pretty switch of the git log provides a multitude of ways to format git log output, especially when the custom string is used. For example, if you simply provide the string %ad as the parameter to the pretty switch, you will see the git log graph with nothing but commit dates next to the branch and merge points.

The %h string will display nothing but a short commit hash, and %s will display nothing but the commit message next to the git log graphs’ commit points

graph@log:~$ git log –graph –pretty=”%h” –date=short

graph@log:~$ git log –graph –pretty=”%s” –date=human

If you wanted to get real crazy you could even start coloring coding the display with a git log graph call like the one that follows:

git log --graph --pretty="%C(yellow) Hash: %h %C(blue)Date: %ad %C(red) Message: %s " --date=human
git log graph example

Combine the pretty option and a custom string with git log graph

Git log graph examples

The following images show the git log graph output for these commands:

  • git log --graph --pretty="%ad" --date=short
  • git log --graph --pretty="%C(yellow) %s"
  • git log --graph --pretty="%C(bold green) %(ar)"
  • git log --graph --pretty="%C(bold blue)%h" --decorate --all
git log graph date

Git log graph with just the date showing.

git log graph color

Change the color of the git log graph output to yellow.

git log graph %ar

Use the pretty %ar switch with git log graph pretty.

decorate all git log graph

 

 

 

 

 

 

 

 

 

 

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchAppArchitecture

SearchSoftwareQuality

SearchCloudComputing

SearchSecurity

SearchAWS

Close