git log. For a compact view use git log --oneline, and git log --oneline --graph --all to see how branches diverge and merge.Guide
Every commit you make is searchable. Here's how to read a project's past — what changed, when, and by whom.
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
$ git log Tip: git log opens in a pager. Scroll with arrows, press q to quit.
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
$ 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 --oneline shows a short hash + message per line. Add --graph --all to see how branches diverge and merge.
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
$ 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 The double dash ( -- ) separates options from file paths so Git doesn't confuse them.
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
$ git show a1b2c3d
$ git show HEAD # the latest commit
$ git show HEAD~2 # two commits before HEAD HEAD~1 means 'one commit before HEAD', HEAD~2 'two before', and so on.
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
$ 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 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.
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
$ git blame src/app.js 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
git log. For a compact view use git log --oneline, and git log --oneline --graph --all to see how branches diverge and merge.git show <commit-hash> prints that commit's message and full diff. Get the hash from git log --oneline.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.git blame <file> annotates every line with the commit, author and date that last changed it — handy for understanding why a line is there.