Lesson

Git History

10 min reading
Free Course

Git History: Exploring Commits and File Differences

Git stores every commit as an interconnected chain of snapshots, and git log, git show, and git diff let you trace exactly when a line changed and who wrote it. Learning history commands turns debugging regressions from guesswork into a quick terminal search.

Viewing Commit Logs Cleanly

Running plain git log displays full commit hashes, author emails, dates, and messages in reverse chronological order. Add formatting flags to scan dozens of commits in seconds:

git log --oneline
git log --oneline --graph --decorate --all
git log --stat -n 5
  • --oneline condenses each commit to its short hash and subject line.
  • --graph --decorate --all draws branch forks and merges in ASCII art.
  • --stat lists modified files alongside inserted and deleted line counts.

Filtering Commits by Author, Date, or File

Narrow down long histories when hunting for a specific regression:

git log --author="Amina" --since="2 weeks ago"
git log --oneline -- styles.css
git log -S "banner.svg" --oneline

The -S flag (pickaxe search) finds every commit that added or removed a specific string in your codebase.

Inspecting Snapshots and Comparing Diffs

Use git show <hash> to print the commit metadata and full line-by-line patch of any single commit. Use git diff to compare working edits, staged changes, or two commits:

git show 221ec6e
git diff
git diff --staged
git diff main..feature/header-nav

Common History Inspection Mistakes

Running git diff after git add returns empty output because git diff compares working files against the staging area by default. Always pass --staged when inspecting changes already added to the index.

Frequently Asked Questions

How do I exit git log when it opens a pager?

Press q to quit the less pager immediately. While browsing, press Space to scroll down, b to scroll up, and /keyword followed by Enter to search.

How do I see who last edited each line of a file?

Run git blame styles.css to view the commit hash, author, and timestamp next to every line in the file.

What is the difference between git diff A..B and git diff A...B?

Two dots (A..B) compare the tips of branch A and branch B directly. Three dots (A...B) compare the changes on branch B since it diverged from branch A.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum