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
git add
Stages file changes into the index so they are included in the next commit. Supports whole files, directories, and interactive patch selection.
git log
Displays commit history in reverse chronological order with filters for author, date, path, or content. The primary tool for exploring project history.
git reset
Moves the current branch tip to a specified commit, optionally updating the index and working tree. Used to unstage files or rewind local history.
git clone
Downloads a repository from a remote URL into a new local directory, setting up the remote 'origin' automatically. Includes all commits, branches, and tags by default.
git init
Creates a new empty Git repository by initializing the .git metadata directory in the current or specified folder. Turns any directory into a version-controlled project.