By default when you use the git log command without any options, you would see details for each commit in multiple lines with details such as
- 40-character long commit hash (where the head is pointing)
- Author details, username followed by the author email ID
- Date
- Commit comment
% git log
commit 6ac92d6dece8c15b9472da2590a23f58ff48b4f9 (HEAD -> main)
Author: c2c
Date: Tue Jan 24 18:14:47 2023 +0000
4th commit
commit 06250f0b1cdb7054863f1307d6e66fa8fadda81d
Author: c2c
Date: Tue Jan 24 18:14:34 2023 +0000
3rd commit
commit 27125141f5e0d692e80df0c3113d68334523e539
Author: c2c
Date: Tue Jan 24 14:21:48 2023 +0000
2nd commit
commit a3e24f41e70dec79395c730d68bf26ce64dd7444
Author: c2c
Date: Tue Jan 24 14:21:38 2023 +0000
1st commit
This could easily become hard to read when there are multiple branches and lots of commits.
You can easily make the commit logs to be one/line by using the option --oneline
% git log --oneline
6ac92d6 (HEAD -> main) 4th commit
06250f0 3rd commit
2712514 2nd commit
a3e24f4 1st commit
As you may see that with --oneline option, the commit logs are readable but miss a lot of crucial information such as commit time, author, etc.
Ways to show git commit log in a better way
Example 1: Using pretty formatting
Let's try to get all the information that we need in one line with pretty format options,
% git log --graph --pretty=format:'%h - %s (%cr) - %an'
* 6ac92d6 - 4th commit (25 minutes ago) - c2c
* 06250f0 - 3rd commit (25 minutes ago) - c2c
* 2712514 - 2nd commit (4 hours ago) - c2c
* a3e24f4 - 1st commit (4 hours ago) - c2c
%h -> abbreviated commit hash
%s -> subject (commit message)
%cr -> committer date, relative
%an -> author name

Example 2: Adding Colors
% git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%s%Creset (%cr) - %Cblue%an%Creset'
* 6ac92d6 - 4th commit (36 minutes ago) - c2c
* 06250f0 - 3rd commit (37 minutes ago) - c2c
* 2712514 - 2nd commit (4 hours ago) - c2c
* a3e24f4 - 1st commit (4 hours ago) - c2c
Color Options
- %Cred: Set red color
- %Cgreen : Set green color
- %Cblue: Set blue color
- %Creset : To reset the color

Example 3: Creating an alias for the log formatting in bash/zsh profile
Na! There is no way one can remember or type such huge formatting strings each time you want to see the commit logs. It's always better to come up with your preferred way of a formatting string and add them as an alias to the bash/zsh profile,
Open the .zshrc file or the .bash_profile file and create an alias like below,
alias gitlog1="alias gitlog1="git log --graph --pretty=format:'%Cred%h%Creset - %Cblue%s%Creset (%cr) - %Cblue%an%Creset'"
alias gitlog2="git log --graph --pretty=format:'%h - %s (%cr) - %an'"
Invoke custom git log alias,
% gitlog1
* 6ac92d6 - 4th commit (44 minutes ago) - c2c
* 06250f0 - 3rd commit (44 minutes ago) - c2c
* 2712514 - 2nd commit (5 hours ago) - c2c
* a3e24f4 - 1st commit (5 hours ago) - c2c
Custom multiline log example
Use the %n option to add a newline,
% git log --graph --pretty=format:'Commit: %h %nComment: %s %nDate:%ci (%cr) %nAuthor Name: %an %nAuthor Email:%ae %nCommenter Name:%cn %nCommenter Email:%ce'
* Commit: 6ac92d6
| Comment: 4th commit
| Date:2023-01-24 18:14:47 +0000 (54 minutes ago)
| Author Name: c2c
| Author Email:c2c@c2c.com
| Commenter Name:c2c
| Commenter Email:c2c@c2c.com
* Commit: 06250f0
| Comment: 3rd commit
| Date:2023-01-24 18:14:34 +0000 (54 minutes ago)
| Author Name: c2c
| Author Email:c2c@c2c.com
| Commenter Name:c2c
| Commenter Email:c2c@c2c.com
* Commit: 2712514
| Comment: 2nd commit
| Date:2023-01-24 14:21:48 +0000 (5 hours ago)
| Author Name: c2c
| Author Email:c2c@c2c.com
| Commenter Name:c2c
| Commenter Email:c2c@c2c.com
* Commit: a3e24f4
Comment: 1st commit
Date:2023-01-24 14:21:38 +0000 (5 hours ago)
Author Name: c2c
Author Email:c2c@c2c.com
Commenter Name:c2c
Commenter Email:c2c@c2c.com
More Options:
- %ci -> Commit time in ISO format
- %cn -> Commiter name
- %ce -> Commiter email
Also do checkout the git doc page for pretty formatting: https://git-scm.com/docs/pretty-formats/2.39.0
Facing issues? Have Questions? Post them here! I am happy to answer!
- Change the default git branch name from master to main
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- How to Install Git on Windows
- Setup Git + Visual Studio Code Tutorial
- How to undo last Git Commit on Local Repository?
- Install GitHub Command Line Tool on Mac
- How to Create a Git Branch in 6 Different ways
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows
- Git Config Command - A Deep Dive
- Step-by-Step: How to delete a git branch from local as well as remote origin
- How to Add Git Bash Option to Windows Terminal List
- Command to Clone Repository Using Git Bash
- How to remove or unstage a file from git staged area
- Get the file location of git config values
- GitHub: How to Search Code
- How to check your installed version of Git
- Fix: error: src refspec master does not match any failed to push some refs to Git
- Git: Step-by-Step - How to Push Local Brach to GitHub
- How to Merge Branch into Master Branch
- fix fatal: --local can only be used inside a git repository error
- Fix: Git Pull Error: unable to resolve reference refs/remotes/origin/master: reference broken
- Change the default diff or commit editor for git
- Git Fix: fatal: refusing to merge unrelated histories Error
- Spring Boot + Redis Cloud Configuration and Setup Tutorial - Java
- How to create SharePoint Online List Item using REST API - SharePoint
- Programmatically check if Facebook is installed on Android device - Android
- How to Split a String in Python? - Python
- How to open CMD for current file/folder location in Notepad++ - NotepadPlusPlus
- [Solution] IntelliJ: Cannot find declaration to go to, Nothing here, Java file outside of source root Errors - Java
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ - Java
- Fix: Missing the following required SSO configuration values: sso_start_url, sso_region - AWS