basics

git commit

Records the staged snapshot to the repository history along with a message and author metadata. Every commit is identified by a unique SHA hash.

git commit [-m <msg>] [<options>]

Common flags

Flag Purpose
-m <msg> Provide the commit message inline
-a / --all Auto-stage tracked, modified files before committing
--amend Replace the previous commit with a new one
--no-edit Use with --amend to keep the existing message
-S GPG-sign the commit
--fixup=<commit> Create a fixup commit for use with autosquash rebase

Examples

git commit -m "Add login form"

Commit staged changes with a message

git commit -am "Fix typo"

Stage tracked files and commit in one step

git commit --amend --no-edit

Fold new staged changes into the last commit

Gotcha

Never --amend a commit you have already pushed to a shared branch; it rewrites history and forces collaborators to reset.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge