GitLab Git Associate study materials
GitLab Git Associate study resources

GitLab Git Associate: History and inspection

GitLab Git Associate · Work through your exam, one topic at a time.

All guide sections

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 --all shows a compact graph with refs; add -p for patches, --stat for file summaries, -n to limit, and filters such as --author, --since, and --grep.
  • git diff compares the working tree with the index; git diff --staged compares the index with HEAD; git diff HEAD compares the working tree with HEAD.
  • git blame -L 10,20 file attributes each line to the last commit that changed it. -C can 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 diff to show staged changes.
  • Using reset --hard on a shared branch, then force-pushing.
  • Believing revert deletes the original commit.
  • Reading blame as the original author of each line rather than the last change.