Viewing History

The history is just a list of commits

Each commit stores a snapshot, an author, a date and a message. git log walks that chain backwards from where you are (HEAD) and prints it. By default it's verbose — one block per commit. Press q to quit the viewer.

See the full history

Terminal
$ git log
In VS Code
  1. Open the Timeline view: click a file, then the Timeline section at the bottom of the Explorer
  2. Or install the popular Git Graph / GitLens extension for a visual log

Tip: git log opens in a pager. Scroll with arrows, press q to quit.

Make the log readable

Nobody reads the full log all day. These flags make it scannable — --oneline is the one you'll use most, and --graph --all draws the branch structure.

Compact and visual views

Terminal
$ git log --oneline
$ git log --oneline --graph --all
$ git log --stat        # which files changed
$ git log -p             # full diffs per commit
$ git log -n 5           # just the last 5
In VS Code
  1. The Git Graph extension shows this branch diagram with one click
  2. Hover a commit to see its message, author and changed files

--oneline shows a short hash + message per line. Add --graph --all to see how branches diverge and merge.

Find a specific commit

You can filter the log by who, when, which file, or even by the text that changed. That last one — the "pickaxe" — is a lifesaver for "when did this line appear?".

Filter the history

Terminal
$ git log --author="Asha"
$ git log --since="2 weeks ago"
$ git log --oneline -- src/app.js   # commits touching one file
$ git log -S"functionName"          # commits that added/removed this text
$ git log --grep="login"            # search commit messages
In VS Code
  1. GitLens adds a searchable commit list and file history
  2. Right-click a file → Open Timeline to see only its commits

The double dash ( -- ) separates options from file paths so Git doesn't confuse them.

Look at one commit: git show

Once you've spotted a commit (by its short hash in the log), git show prints its message and the exact changes it made.

Inspect a single commit

Terminal
$ git show a1b2c3d
$ git show HEAD          # the latest commit
$ git show HEAD~2        # two commits before HEAD
In VS Code
  1. In Git Graph / Timeline, click a commit to open its diff
  2. Each changed file shows old vs new side by side

HEAD~1 means 'one commit before HEAD', HEAD~2 'two before', and so on.

Compare versions: git diff

git diff shows differences. With no arguments it compares your unstaged edits against the last commit. You can also compare staged changes, two branches, or two commits.

See what differs

Terminal
$ git diff                 # working tree vs last commit (unstaged)
$ git diff --staged        # what's staged for the next commit
$ git diff main..feature   # how feature differs from main
$ git diff HEAD~2 HEAD     # changes across the last two commits
In VS Code
  1. Click any changed file in the Source Control panel for a side-by-side diff
  2. To compare branches, use Git Graph → right-click a branch → Compare

Staged vs unstaged: plain git diff hides anything you've already git add-ed. Use git diff --staged to review exactly what your next commit will contain.

Who wrote this line? git blame

git blame annotates every line of a file with the commit, author and date that last changed it. Despite the name it's not about blaming anyone — it's how you find the context behind a line ("why is this here?") so you can read that commit's message.

Trace each line to a commit

Terminal
$ git blame src/app.js
In VS Code
  1. Enable GitLens — it shows an inline 'blame' annotation on the current line as you move the cursor
  2. Hover it to see the commit message and author

Found the commit hash from blame? Run git show <hash> to read the whole change.

Up next: where Git really shines — branches, so you can build a feature on the side without touching working code.

FAQ

Frequently Asked Questions

How do I see my commit history?
Run git log. For a compact view use git log --oneline, and git log --oneline --graph --all to see how branches diverge and merge.
How do I see what changed in a specific commit?
git show <commit-hash> prints that commit's message and full diff. Get the hash from git log --oneline.
What is the difference between git log and git diff?
git log lists commits — the history. git diff shows the actual line-by-line changes between two states, such as your current edits versus the last commit.
How do I find out who changed a line?
git blame <file> annotates every line with the commit, author and date that last changed it — handy for understanding why a line is there.