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.
What you learned
Section titled “What you learned”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 diff — git 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 depth — git 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.
Command reference
Section titled “Command reference”| Command | What it does |
|---|---|
git status | Full working-tree state: staged, unstaged, untracked |
git status -s | Compact two-column status summary |
git diff | Unstaged changes (working tree vs. staging area) |
git diff --staged | Staged changes (staging area vs. last commit) |
git diff HEAD | All 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 log | Full commit history, most recent first |
git log --oneline | Compact: one line per commit |
git log --oneline --graph --all | Branch 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 --stat | Include file-change summary per commit |
git show <hash> | Full diff for a single commit |
git log -- <file> | History for a specific file |
What’s next — Branching
Section titled “What’s next — Branching”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.