Write the index into a new commit object on the current branch.
Snapshot the current index state into a new commit object on the current branch. The commit captures: the tree, your name/email, a timestamp, parent commit(s), and a message. The branch tip is updated to the new commit.
commit is the orchestrator of three plumbing operations: write-tree (turn the index into a tree object), commit-tree (wrap that tree + metadata into a commit object), and update-ref (move the current branch pointer to the new commit). The previous tip becomes the parent. HEAD follows along because it's a symbolic ref.
git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
[--dry-run] [(-c | -C | --squash | --fixup) <commit>]
[-F <file> | -m <msg>] [--allow-empty] [--allow-empty-message]
[--no-verify] [-e] [--author=<author>] [--date=<date>]
[--cleanup=<mode>] [--[no-]status] [-i | -o]
[--pathspec-from-file=<file>] [-S[<keyid>]]
[--] [<pathspec>...]| Flag | What it does |
|---|---|
-m "<msg>" | Inline commit message. Use -m "summary" -m "body" for multi-paragraph. |
-a, --all | Stage all tracked modifications and deletions before committing. Doesn't pick up new files. |
--amend | Replace the previous commit (or augment it). Rewrites history — never on shared branches. |
-s, --signoff | Append Signed-off-by: Name <email>. Required by some projects (the kernel, etc.). |
-v, --verbose | Show the full diff in the editor when composing the message. Encourages reading what you're committing. |
--no-verify | Skip pre-commit and commit-msg hooks. ⚠️ Almost always wrong. |
-S | GPG/SSH-sign the commit. |
--allow-empty | Permit a commit with no changes. Useful for triggering CI. |
--fixup=<commit> | Create a fixup! commit destined to be squashed into <commit> on a later interactive rebase. |
--amend).-s).--allow-empty -m 'rebuild').$ git add src/main.c
$ git commit -m 'parse: handle empty header'$ git commit -m 'parse: handle empty header' \
-m 'Previously segfaulted on requests with no headers. Empty header maps to an empty string.'$ git add forgotten.c
$ git commit --amend --no-editgit rebase -i --autosquash.$ git commit --fixup=<sha> --no-editadd foo, not added foo. Title ≤ 72 chars. Body wraps at 72.--amend after pushing unless you're comfortable force-pushing with --force-with-lease and your team is OK with it.--fixup + git rebase -i --autosquash instead of squashing manually. Robust and reviewable.--no-verify. Fix the hook or remove it; don't bypass it.git commit -a does not stage new files. People hit this and think their commit is empty.--allow-empty-message. There's a reason for that.user.email lets you commit, but the commits have whatever default Git guessed. Fix with git config --global user.email "you@host".Hit each option, then Check answers. Score is recorded; Next is always open.