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
Have Questions? Post them here!
- How to ignore files in git using .gitignore file
- How to update expired GitHub token on local git remote config
- How to undo last Git Commit on Local Repository?
- Git Commit - Author identity unknown, Please tell me who you are email
- Git: Step-by-Step - How to Push Local Brach to GitHub
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- Remove git config at Local, Global or System Levels?
- Change the default git branch name from master to main
- fix fatal: --local can only be used inside a git repository error
- Git Remove Untracked Files using Command
- How to remove or unstage a file from git staged area
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows
- Fix [oh-my-zsh] Cant update: not a git repository
- Get List of all local branches git command
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- [fix] fatal: this operation must be run in a work tree in git
- How to Install Git on Windows
- Perform an Empty Commit in Git without anything in Staging Area
- Rename git branch on Local and GitHub Remove using Command
- Fix: error: could not lock config file /etc/gitconfig: Permission denied
- Get the file location of git config values
- Git: Delete Branch Locally and Remotely at Origin
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- Github: How to Invite Collaborators
- How to change directory in Git bash
- Can Microsoft SharePoint Lists be synced and accessed offline without internet? - SharePoint
- [Java] Error: Unmappable character for encoding UTF-8. Save could not be completed. - Java
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs - Python-Programs
- Convert Multidimensional Array toString In Java - Java
- How to upgrade PowerShell on Mac - Powershell
- No Android device found : Android File Transfer App Mac OS X - Android
- How to enable Auto-Save Files in VS Code - HowTos
- How to fix Java HTTP java.net.UnknownHostException - Java