Git Reference
Git Reference / Staging & committing

04Staging & committing

The staging area lets you craft exactly what goes into each commit — even individual lines of a file.

See what changed

Status overview and line-level diffs.

git status -sb
git diff              # unstaged changes
git diff --staged     # what will be committed
git diff --word-diff  # inline word changes

Stage changes

Choose what goes in the next commit.

git add file.txt
git add .              # everything in this dir
git add -p             # pick hunks interactively
git add -u             # tracked files only

Commit

Record the staged snapshot.

git commit -m "Add login form"
git commit -am "Fix typo"   # stage tracked + commit
git commit --amend          # edit the last commit
git commit --amend --no-edit

Move & delete files

Let Git track renames and removals.

git mv old.js new.js
git rm file.txt
git rm --cached secrets.env  # untrack, keep on disk
Good commit messagesShort imperative summary (≤50 chars), blank line, then the why. “Fix race in session refresh” beats “fixed stuff”.