skip to content
Alvin Lucillo

Display commit history as graph

/ 1 min read

To display the commit history as graph, use --graph argument in git log. The commit commands below are then shown in the git log statement, specifically showing where commits diverged from.

git init -b main

git commit --allow-empty -m "Major version 1"
git commit --allow-empty -m "Major version 2"
git commit --allow-empty -m "Major version 3"

git switch -c feature1
git commit --allow-empty -m "Feature 1: version 3.1"
git commit --allow-empty -m "Feature 1: version 3.2"

git switch main
git switch -c feature2
git commit --allow-empty -m "Feature 2: version 3.1"
git commit --allow-empty -m "Feature 2: version 3.2"
git log --graph --oneline --decorate --all

* 63b4237 (feature2) Feature 2: version 3.2
* 326cd74 Feature 2: version 3.1
| * 14289f7 (feature1) Feature 1: version 3.2
| * fc08836 Feature 1: version 3.1
|/  
* c81ce21 (HEAD -> main) Major version 3
* 864bd19 Major version 2
* 7967f89 Major version 1
(END)