git log

Inspection & Comparison

Show commit logs


The 'git log' command shows the commit history of your repository. It displays commits in reverse chronological order (newest first), showing commit hash, author, date, and message. With various options, you can customize the output format, filter commits, and follow file history. Essential for understanding project history and finding specific changes.

Synopsis

git log [<options>] [<revision-range>] [[--] <path>...]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (4)

Shorthand for --pretty=oneline --abbrev-commit. Shows each commit on a single line with abbreviated hash.

RecommendedCompact one-line history — the best everyday overview

Example

git log --oneline

Draw a text-based graphical representation of the commit history. Shows branch and merge structure visually.

RecommendedShows where branches fork and merge; pair with --oneline

Example

git log --oneline --graph

Show commits reachable from all refs - every local branch, remote-tracking branch and tag (plus the stash) - not just HEAD. Essential when combined with --graph.

RecommendedWith --graph, shows every branch, tag and remote-tracking ref

Example

git log --oneline --all

Limit the number of commits shown. -n 5 shows only the 5 most recent commits; -5 and --max-count=5 are equivalent forms.

RecommendedLimits output to the latest N commits

Example

git log -n 5

Intermediate (2)

Show the diff (patch) introduced by each commit. See exactly what changed in each commit. Merge commits show no diff by default.

When neededFull diffs are long; combine with -n or a path. Merges show no diff by default

Example

git log -p

Filter commits whose author name or email matches the pattern (a case-sensitive regex; add -i to ignore case). Useful for seeing what a specific person has written.

When neededFilters by author: case-sensitive regex, add -i to ignore case

Example

git log --author="John"

Choosing the Right Option

Log Output Formats

Choose the right format for your needs

CommandShowsVerbosityBest For
git logFull detailsHighDetailed review
git log --onelineHash + messageLowQuick overview
git log --statFiles changed per commitMediumSee scope of changes
git log -pFull diffVery highCode review

Filtering Commits

Find specific commits in history

CommandFilter ByExample
--authorPerson who wrote the commit (author; use --committer for committer)--author="John"
--since/--untilDate range--since="2024-01-01"
--grepCommit message--grep="fix"
-- <path>Files changed-- src/app.js

Log vs Reflog

Understanding when to use each

CommandShowsSurvives Reset?Use For
git logCommit history on branchNoNormal history viewing
git reflogAll HEAD movementsYesRecovering lost commits

Examples

View recent commits

git log

Shows full commit history with hash, author, date, and message.


Compact one-line view

git log --oneline

Shows each commit on one line with short hash and message.


View file history

git log -- path/to/file.js

Shows only commits that changed the specified file.


Visual branch graph

git log --oneline --graph --all

Shows a text-based graph of all branches and their commits.

Workflow Examples

1
git log --oneline -10

Quick view of last 10 commits

2
git log -p -1

See full diff of most recent commit

1
git log --oneline -- path/to/file.js

List commits that changed this file

2
git log -p -- path/to/file.js

See the actual changes made

3
git blame path/to/file.js

See who wrote each line

1
git log --oneline --graph --all

Full branch visualization

2
git log --oneline --graph main..feature

Commits in feature not in main

Troubleshooting

Log output is too long / can't exit

Cause: Git uses 'less' pager by default

Press 'q' to quit. Use -n to limit commits, or pipe to head: git log --oneline | head -20

Don't see commits from other branches

Cause: Git log only shows commits reachable from HEAD (your current branch) by default

Use --all flag: git log --oneline --all

Can't find a commit I know exists

Cause: Commit might be on different branch or was reset

Try git reflog to see all recent HEAD positions, including after resets

Log shows too much / too little information

Cause: Default format might not suit your needs

Use --oneline for brief, -p for detailed, --stat for file summary

Tips & Pitfalls

Best Practices

  • ✓Use --oneline for quick overviews, full log for detailed review
  • ✓Combine --graph --all --oneline for a complete branch visualization
  • ✓Use -n to limit output when you only need recent commits
  • ✓Filter by author, date, or path to find specific changes
  • ✓Use git log main..feature to see commits unique to a branch

Common Mistakes

  • ✗Not knowing you can press 'q' to quit the log viewer (uses less pager by default).
  • ✗Forgetting --all when wanting to see commits from all branches, not just current.
  • ✗Using git log when you need git reflog - log shows commit history, reflog shows all ref changes including resets.
  • ✗Not using -- before file paths, which can cause ambiguity with branch names.

FAQ

A:

Press 'q' to quit. Git log uses the 'less' pager. You can also use -n flag to limit output or pipe to head.

A:

Use --all flag: git log --oneline --all. Without it, you only see commits reachable from your current branch (HEAD).

A:

Use -p (patch) flag: git log -p. Add -1 to see just the most recent: git log -p -1

A:

Use --author: git log --author="name". Matches partial names and emails (case-sensitive; add -i to ignore case).

A:

Log shows commit history. Reflog shows all HEAD movements including resets. Use reflog to recover 'lost' commits.