On branch main
Changes not staged for commit:
modified: app.js
Untracked files:
utils.js
# Short format:
M app.js
?? utils.js
Note The short flag (-s) gives a compact two-column output: left column = staging area, right column = working tree. M = modified, A = added, ? = untracked, D = deleted.
Note git add . stages new and modified files in the current directory and below. git add -A stages everything including deletions from anywhere in the repo. Prefer staging specific files to avoid accidentally committing secrets or large binaries.
stage filesadd to stagingprepare committrack filegit add
Stage Part of a File
syntax
git add -p [file]
example
git add -p utils.js
# Git shows each hunk and asks:# Stage this hunk [y,n,q,a,d,s,e,?]?# y = stage, n = skip, s = split into smaller hunks
Note Extremely useful when a file has multiple unrelated changes. You can commit them separately for a cleaner history. Use 's' to split a hunk if Git grouped too many changes together.
partial stagestage part of fileinteractive addstage hunkselective staging
Commit Staged Changes
syntax
git commit [-m "message"]
example
git commit -m "Add user authentication endpoint"# Multi-line message:git commit -m "Fix cart total calculation
The discount was applied after tax instead of before.
Updated the order of operations in calculateTotal()."
Note Without -m, Git opens your configured editor for the message. A good commit message has a short summary line (under 72 chars), a blank line, then optional details.
[main f4e5d6c] Update API response format
1 file changed, 12 insertions(+), 8 deletions(-)
Note The -a flag only stages already-tracked files that have been modified or deleted. It will NOT add new untracked files. You still need git add for brand new files.
quick commitcommit all modifiedstage and commitshortcut commit
View Unstaged Changes
syntax
git diff [file]
git diff --staged [file]
example
# Changes in working tree (not yet staged):git diff
# Changes that are staged for the next commit:git diff --staged# Diff for a specific file:git diff src/auth.js
Note Plain git diff shows only unstaged changes. Use --staged (or --cached, they're identical) to see what will go into the next commit. If git diff shows nothing, your changes are probably already staged.
see diffview changeswhat did i changecompare changesshow modifications
Note -s shows only counts (no commit messages), -n sorts by number of commits (most first), -e includes email addresses. Handy for seeing who contributed most.
commits by authorwho committedcontributor summarycommit count per person