---
title: "Git History and Diffs Cheatsheet | FindUtils"
description: "Inspect Git history, compare revisions, follow file changes, and read reflogs. Check the difference between log ranges and snapshot comparisons."
url: https://findutils.com/cheatsheets/git-history/
---

# Git History and Diffs Cheatsheet

Inspect Git history, compare revisions, follow file changes, and read reflogs. Check the difference between log ranges and snapshot comparisons. 38 commands in 7 sections, filed under [Git & Version Control](https://findutils.com/cheatsheets/git/).

## Read this first

- `<commit>, <branch>, <file>`: Replace each placeholder with a real revision, branch, or path
- `Read-only reference`: These inspection commands do not change tracked files or commits
- `A..B versus A...B`: Log ranges select commits; diff ranges compare file snapshots
- `Saved commits only`: History cannot recover edits that Git never recorded

## Inspect local changes

- `git status --short --branch`: Show file state and branch tracking
- `git diff -- <file>`: Compare an unstaged file with the index
- `git diff --cached -- <file>`: Compare staged content with HEAD
- `git diff HEAD -- <file>`: Compare the working file with the last commit
- `git diff --stat`: Summarize unstaged changes by file
- `git diff --check`: Check unstaged changes for whitespace errors

## Read commit history

- `git log -10 --oneline`: List the ten most recent commits
- `git log --all --graph --decorate --oneline`: Show reachable branch history as a graph
- `git log --first-parent --oneline`: Follow the first parent through merge commits
- `git log --since="2 weeks ago" --oneline`: Filter history by a relative date
- `git log --author="Alex" --oneline`: Match the author with a regular expression
- `git log --grep="timeout" --oneline`: Find commit messages that match the pattern

## Compare revisions

- `git diff main feature --`: Compare the two branch tips
- `git diff main...feature --`: Compare the merge base with the feature tip
- `git log main..feature --oneline`: List feature commits absent from main
- `git log --left-right main...feature --oneline`: Show commits unique to either branch
- `git diff --name-status HEAD~1 HEAD --`: List changed paths and status in the last commit
- `git show --stat <commit>`: Show a commit summary and file statistics

## Follow one file

- `git log --follow --oneline -- <file>`: Follow one file across detected renames
- `git log -p -- <file>`: Show patches from the file history
- `git log -S"timeout" -- <file>`: Find commits that change the count of this exact text
- `git log -G"timeout.*=" -- <file>`: Find added or removed lines that match the regex
- `git blame -L 10,20 -- <file>`: Show the last recorded change for lines 10 through 20
- `git show HEAD:<file>`: Read a repository-relative path from the last commit

## Inspect saved references

- `git reflog show --date=iso HEAD`: List local HEAD movements while their reflog entries remain
- `git show --format=fuller --no-patch <commit>`: Show author and committer metadata
- `git branch --contains <commit>`: List local branches that contain the commit
- `git tag --contains <commit>`: List tags whose history contains the commit

## Sources and related references

- `https://git-scm.com/docs/git-log`: Check revision filters and history ranges
- `https://git-scm.com/docs/git-diff`: Check snapshot comparison and merge-base behavior
- `https://git-scm.com/docs/git-blame`: Check line attribution and rename handling
- `https://git-scm.com/docs/git-reflog`: Check local reflog scope and expiry
- `/cheatsheets/git-branches-remotes/`: Continue with branches and remote tracking
- `/cheatsheets/gitignore-patterns/`: Check ignored-file rules

## Related

- Cheatsheet: [Git Branches and Remotes](https://findutils.com/cheatsheets/git-branches-remotes/)
- Cheatsheet: [Gitignore Patterns](https://findutils.com/cheatsheets/gitignore-patterns/)
- Cheatsheet: [Git Commands](https://findutils.com/cheatsheets/git-commands/)
