You have been making commits, building your project's story one snapshot at a time. But commits are not just for saving, they are for understanding. When something breaks, when you need to know who changed what, or when you simply want to see how your project evolved, you need to read that history.
Git keeps a complete, detailed log of everything that has ever happened in your repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.. Every commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed., every author, every change, it is all there. The challenge is not finding the information; it is knowing how to access it efficiently.
The basic log command
The simplest way to view history:
git logRun this command and you will see something like:
commit a1b2c3d4e5f6789012345678901234567890abcd
Author: Sarah Chen <sarah@example.com>
Date: Mon Jan 15 14:32:10 2024 -0500
Add user authentication to login page
Implemented JWT token storage and validation
for the login form. Added error handling for
invalid credentials.Each commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. shows:
- Commit hash: The unique identifier (SHA) for this commit
- Author: Who made the changes and their email
- Date: When it happened
- Message: What they did and why
Press q to quit the log viewer when you are done.
Navigating the log
The basic git log output can be long. Here is how to move through it:
| Key | Action |
|---|---|
Space or f | Next page |
b | Previous page |
j or down arrow | Next line |
k or up arrow | Previous line |
/search | Search for text |
q | Quit |
git log. On a real project with thousands of commits, that command dumps an overwhelming wall of text. Always add --oneline or -n to keep the output manageable. AI tends to skip the practical flags you actually need.Compact one-line view
The full log is great for details, but often you just want a quick overview:
git log --onelineOutput:
a1b2c3d Add user authentication to login page
e4f5g6h Fix navigation responsive layout
i7j8k9l Update README with setup instructions
m2n3o4p Initial commit: project setupEach commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. fits on one line: short hash (first 7 characters) and the first line of the commit message. This is perfect for scanning history quickly.
Limiting the output
Large projects have hundreds or thousands of commits. You rarely need to see all of them at once.
git log -5 # Last 5 commits
git log -10 # Last 10 commits
git log -20 --oneline # Last 20 commits, compact viewFilter by time
git log --since="1 week ago"
git log --since="2024-01-01"
git log --until="yesterday"Visualizing branches
When you are working with multiple branches and merges, a simple list does not show the whole story:
git log --graph --oneline --allThis shows:
* a1b2c3d Merge pull request #42 from feature/user-auth
|\
| * b2c3d4e Add password validation
| * c3d4e5f Create login form component
|/
* d4e5f6g Fix CSS loading issue
* e5f6g7h Update dependencies| Flag | What it adds |
|---|---|
--graph | Shows branch/merge visualization |
--oneline | Compact one-line format |
--all | Includes all branches, not just current |
--decorate | Shows branch/tag names |
Filtering your history
Sometimes you need to find specific commits in a sea of history.
Filter by author
git log --author="Sarah"
git log --author="sarah@example.com"Filter by file
git log -- README.md
git log -- src/auth.jsSearch commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. messages
git log --grep="fix"
git log --grep="login" --onelineCombining filters
# Commits by Sarah in the last month mentioning "bug"
git log --author="Sarah" --since="1 month ago" --grep="bug"Custom formats
The default output is fine, but sometimes you want specific information displayed your way.
git log --pretty=format:"%h - %an, %ar : %s"Output:
a1b2c3d - Sarah Chen, 2 days ago : Add user authentication
e4f5g6h - Mike Ross, 5 days ago : Fix navigation responsive layout| Placeholder | What it shows |
|---|---|
%h | Short hash (7 chars) |
%H | Full hash (40 chars) |
%an | Author name |
%ar | Relative date ("2 days ago") |
%s | Subject (first line of message) |
Quick reference
| Command | What it shows |
|---|---|
git log | Full commit details |
git log --oneline | Compact one-line format |
git log -5 | Last 5 commits only |
git log --graph --oneline --all | Branch visualization |
git log --author="Name" | Filter by author |
git log --grep="text" | Search commit messages |
git log -- file.txt | Commits affecting specific file |
git log --since="1 week ago" | Recent commits only |
git log --stat | Show change statistics |