History and inspection
This domain tests how to read history and how to undo work safely. Expect command-output questions on log filters, diff targets, blame ranges, tag types, and the difference between revert and reset.
Reading history and diffs
git log --oneline --graph --decorate --allshows a compact graph with refs; add-pfor patches,--statfor file summaries,-nto limit, and filters such as--author,--since, and--grep.git diffcompares the working tree with the index;git diff --stagedcompares the index withHEAD;git diff HEADcompares the working tree withHEAD.git blame -L 10,20 fileattributes each line to the last commit that changed it.-Ccan detect lines moved or copied from elsewhere.
Tags
A lightweight tag is just a ref to a commit. An annotated tag is a separate object with tagger, date, message, and optional signature (git tag -a v1.0 -m release, -s to sign). Tags do not move with new commits.
Undo: revert and reset
git revert <commit> creates a new commit applying the inverse change and is safe for shared history. Reverting a merge needs -m 1 to choose the mainline parent. git reset moves the current branch: --soft keeps index and working tree, --mixed (default) resets the index, and --hard resets both and discards uncommitted work. git reflog can recover commits after a reset.
Worked example
Commit C3 was pushed to main and added a secret. git revert C3 creates C4 that removes the secret while preserving C3 in history. git reset --hard C2 would move only your local main; the remote still has C3, and publishing the reset requires a force push that breaks other clones. Revert is the correct shared-history fix.
Traps that cost marks
- Expecting plain
git diffto show staged changes. - Using
reset --hardon a shared branch, then force-pushing. - Believing
revertdeletes the original commit. - Reading
blameas the original author of each line rather than the last change.