Git Log
What Will We Learn?
- Viewing git commit history.
- Common patterns of viewing history
- Applying custom filters
- git shortlog to see who contributed the most in the project
What is git log For?
git log basically helps you to view your commit history. At it basics it shows enough information for you to know anything about the particular commit which includes:
- Commit hash (SHA-1 identifier)
- Author information (Who is committer?)
- Timestamp (When was the change committed?)
- Commit message (What was commit for?)
A sample example can be:
commit 3c0c5c8a315534b03bcc7134399b84d9441c8e09 (HEAD -> master, origin/master)
Author: Joe Avilez <[email protected]>
Date: Mon Jul 13 23:35:27 2026 +0530
content: add Committing Changes
commit bd0723bee6829dc1a487030f6305d5ccb87af7dc
Author: Joe Avilez <[email protected]>
Date: Mon Jul 13 14:46:15 2026 +0530
content: add How to use `git status`Tip
By default, git log shows all commit. You can pipe it to less to view page by page as git log | less or git log | cat to see in full.
Filtering and Customizing Output
You don’t always want to view full commit log. So apply filtering.
One Line Output
git log --onelineView by Author
Git auto applies global filter *. So, it shows all the commit by the author matching “Joe” prefix.
git log --author="Joe"Graph View
Graph view can be important particularly when working with multiple branches.
git log --graph --decorateTip
Using --oneline with --graph is common pattern.
Exploring Changes
By using -p or --patch option, Git can tell you what changes i.e. diffs for each commit.
git log --patchCommit Affecting Specific File
Sometimes you wanna see commits that introduces changes to particular file. You can see that with -- <file> pattern. For example to see commits that records app.py file, you can:
git log -- app.pyCommit by Message
Search commits affecting a file by message:
git log --grep="fix" -- app.pySearch commits by commit message:
git log --grep="feat"Find When a String Was Added
Ever wondered when a specific word or text first appeared in your project? Git can help.
git log -S "markup"Tip
If you want to match by regex pattern, you can use -G option.
This shows the commits where "markup" was added or removed, making it easy to find when that piece of text entered your codebase.
Filter by Date
git log --since="2 hours ago"
git log --since="1 month ago"This table will help you filtering by date.
| Filter | Command | Description |
|---|---|---|
| Last hour | git log --since="1 hour ago" | Commits from the last hour |
| Today | git log --since="midnight" | Commits since today’s midnight |
| Yesterday | git log --since="yesterday" | Commits since yesterday |
| Last week | git log --since="1 week ago" | Commits from the last week |
| Last month | git log --since="1 month ago" | Commits from the last month |
Customizing with pretty
For your own style of output, you can use --pretty option.
Here are the Common git log --pretty Formats:
| Format | Command | Output |
|---|---|---|
| One line | git log --pretty=oneline | <hash> <message> |
| Short | git log --pretty=short | Author and message |
| Medium (default) | git log --pretty=medium | Standard commit details |
| Full | git log --pretty=full | Includes author and committer |
| Fuller | git log --pretty=fuller | Full details with both dates |
| Reference | git log --pretty=reference | Compact reference format |
git log --pretty=email | Email patch format | |
| Raw | git log --pretty=raw | Raw commit object |
| Custom | git log --pretty=format:"%h %an %ad %s" | Custom output |
Here are the Common format: Placeholders:
| Placeholder | Description |
|---|---|
%h | Abbreviated commit hash |
%H | Full commit hash |
%an | Author name |
%ae | Author email |
%ad | Author date |
%cd | Committer date |
%s | Commit subject |
%b | Commit body |
%d | Refs (branches/tags) |
%cn | Committer name |
Top Custom git log --pretty=format: Examples:
| Purpose | Command |
|---|---|
| Hash + message | git log --pretty=format:"%h %s" |
| Hash + author + message | git log --pretty=format:"%h %an %s" |
| Hash + date + message | git log --pretty=format:"%h %ad %s" --date=short |
| Hash + author + date + message | git log --pretty=format:"%h %an %ad %s" --date=short |
| Full custom (hash, refs, author, relative date, message) | git log --pretty=format:"%C(yellow)%h%Creset %C(cyan)%d%Creset %C(green)%an%Creset %C(blue)%ar%Creset %s" |
Git Shortlog: Contributions per Author
Contributors Summary
Basic usage is git shortlog which shows number of commits per author with commit message.
$ git shortlog
Alice Johnson (3):
Initial project setup
Add authentication
Fix login bug
Bob Smith (2):
Add user profile page
Improve API documentation
Carol Lee (1):
Update READMEWant to know who has contributed the most to a repository? Use git shortlog:
git shortlog -snThis prints a summary of contributors sorted by the number of commits.
Show Contributor Names Only
git shortlog -sneDisplays the commit count, contributor name, and email address.
Contributions in the Last Month
git shortlog -sn --since="1 month ago"Shows who has been most active during the last month.
Contributions by Branch
git shortlog -sn mainSummarizes contributions on the main branch only.
Contributions for a Specific File
git shortlog -sn -- app.pyShows who has contributed commits that affected app.py.