Git & Terminal Cheatsheet
Inspecting History
Use this Git & Terminal reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Reading the Log
git log # full history, newest first (q to quit) git log --oneline # one line per commit git log --oneline --graph --decorate --all # branch topology, worth an alias git log -5 # just the last 5 commits git log -p # history WITH the diffs git log --stat # history with per-file change counts
Searching History
The flags that answer "when did X change and who did it":
git log --author="ada" # by author (substring match) git log --grep="login" # by commit message git log --since="2 weeks ago" # by date (also --until="2026-01-01") git log -S"apiKey" # pickaxe: commits that ADD or REMOVE this string git log -G"use(Memo|Callback)" # commits whose diff matches a regex git log --oneline -- src/auth/ # only commits touching a path git log --follow -- src/old-name.ts # a file's history across renames git log main..feature # commits on feature that main lacks
Inspecting a Single Commit
git show abc1234 # a commit's message and full diff git show HEAD # the most recent commit git show HEAD~2 # two commits before HEAD git show --stat abc1234 # files touched, no diff git show abc1234:src/app.js # a FILE's contents at that commit
HEAD is the commit you have checked out, HEAD~n walks n commits back.
Who Wrote This Line (blame)
git blame src/app.js # last commit + author per line git blame -L 40,60 src/app.js # only lines 40-60 git blame -w src/app.js # ignore whitespace-only changes git log -L 40,60:src/app.js # full HISTORY of those lines, not just latest
Comparing (diff)
git diff # unstaged changes git diff --staged # staged changes git diff main..feature # everything that differs between two branches git diff main...feature # what feature changed since it branched off git diff --stat HEAD~3 # summary vs 3 commits ago git diff --name-only main # just the file names git diff v1.0.0 v1.1.0 -- src/ # between tags, limited to a path
Finding the Breaking Commit (bisect)
Binary-search history for the commit that introduced a bug:
git bisect start git bisect bad # current commit is broken git bisect good v1.2.0 # this old ref was fine # git checks out the midpoint: test it, then answer git bisect good # or: git bisect bad # repeat until it prints the first bad commit git bisect reset # return to where you started
Fully automatic if a command can detect the bug (exit 0 = good):
git bisect start HEAD v1.2.0
git bisect run npm test