Skip to content

Commits and History — Module Recap

Module 02 is complete. You now have the full toolkit for understanding what is happening in your repository at any moment — reading file states, inspecting diffs, building focused commits, writing messages that communicate intent, and navigating history.

git status in depth — Four sections: branch info, staged changes, unstaged modifications, and untracked files. A file can appear in two sections simultaneously when you stage it and then edit it further. git status -s gives a compact two-column summary.

git diffgit diff shows unstaged changes. git diff --staged shows what will be committed. git diff HEAD shows all changes. The unified diff format: - for removed lines, + for added lines, no prefix for context.

The staging area in depthgit add -p for staging individual hunks within a file. git restore --staged <file> to unstage without losing working-tree changes. git restore <file> to discard working-tree changes entirely (destructive). Review git diff --staged before every commit.

Commit messages — Subject line: 50 characters or fewer, capitalized, no period, imperative mood. Body (when needed): explains why, not what; wrapped at 72 characters. Omit -m to write multi-line messages in your editor.

git log — Default: full commits with hash, author, date, message. Key flags: --oneline, --graph, --all, -n, --author, --since, --until, --grep, --stat. git show <hash> shows the full diff for one commit. git log -- <file> filters history to a specific file.

CommandWhat it does
git statusFull working-tree state: staged, unstaged, untracked
git status -sCompact two-column status summary
git diffUnstaged changes (working tree vs. staging area)
git diff --stagedStaged changes (staging area vs. last commit)
git diff HEADAll changes vs. last commit
git add -p <file>Interactively stage individual hunks
git restore --staged <file>Remove a file from the staging area (keep working-tree changes)
git restore <file>Discard working-tree changes for a file (destructive)
git logFull commit history, most recent first
git log --onelineCompact: one line per commit
git log --oneline --graph --allBranch topology view
git log -n <number>Show only the last N commits
git log --author="name"Filter by author
git log --since="date"Filter by date
git log --grep="term"Search commit messages
git log --statInclude file-change summary per commit
git show <hash>Full diff for a single commit
git log -- <file>History for a specific file

Module 03 introduces branches. A branch is a pointer to a commit — creating one lets you develop a feature or fix a bug in isolation without touching the code on main. When the work is ready, you merge the branch back.

Branches are how every professional development workflow is structured. You will create your first branch, switch between branches, make commits on each, and merge them back together.