Git/
Lesson

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 log

Run 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:

KeyAction
Space or fNext page
bPrevious page
j or down arrowNext line
k or up arrowPrevious line
/searchSearch for text
qQuit
AI pitfall
When you ask AI "show me the git history", it often suggests only 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.
02

Compact one-line view

The full log is great for details, but often you just want a quick overview:

git log --oneline

Output:

a1b2c3d Add user authentication to login page
e4f5g6h Fix navigation responsive layout
i7j8k9l Update README with setup instructions
m2n3o4p Initial commit: project setup

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. fits on one line: short hash (first 7 characters) and the first line of the commit message. This is perfect for scanning history quickly.

03

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 view

Filter by time

git log --since="1 week ago"
git log --since="2024-01-01"
git log --until="yesterday"
04

Visualizing branches

When you are working with multiple branches and merges, a simple list does not show the whole story:

git log --graph --oneline --all

This 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

FlagWhat it adds
--graphShows branch/merge visualization
--onelineCompact one-line format
--allIncludes all branches, not just current
--decorateShows branch/tag names
05

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.js

Search 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" --oneline

Combining filters

# Commits by Sarah in the last month mentioning "bug"
git log --author="Sarah" --since="1 month ago" --grep="bug"
06

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

PlaceholderWhat it shows
%hShort hash (7 chars)
%HFull hash (40 chars)
%anAuthor name
%arRelative date ("2 days ago")
%sSubject (first line of message)
07

Quick reference

CommandWhat it shows
git logFull commit details
git log --onelineCompact one-line format
git log -5Last 5 commits only
git log --graph --oneline --allBranch visualization
git log --author="Name"Filter by author
git log --grep="text"Search commit messages
git log -- file.txtCommits affecting specific file
git log --since="1 week ago"Recent commits only
git log --statShow change statistics