Skip to main content
⚡ OpenDevDocs
Git
gitgitGuideBeginner

git commit — Creating Permanent Snapshots

Creating commits in Git: writing semantic commit messages, amending the previous commit (--amend), atomic commits, and commit hashes (SHA-1).

Verified: 2026-09-30
Platforms:
all
#git#commit#conventional-commits#history

git commit — Creating Permanent Snapshots

The git commit command captures a permanent snapshot of the currently staged changes. Each commit receives a unique cryptographic SHA-1/SHA-256 hash that references its parent commits, author identity, timestamp, and message.


1. Syntax and Basic Usage

# 1. Commit with inline message flag (-m):
git commit -m "feat: add dark mode theme toggle to site header"

# 2. Open default text editor for multi-line commit messages:
git commit

# 3. Stage all modified tracked files and commit in one step (-am):
git commit -am "fix: resolve mobile responsive padding overflow"

2. Writing Semantic / Conventional Commits

Adopting Conventional Commits (type(scope): message) makes repository history clean, searchable, and machine-readable for automated changelogs:

PrefixMeaningExample
feat:A new user-facing featurefeat: implement user registration with JWT
fix:A bug fixfix: prevent race condition in event loop
docs:Documentation updates onlydocs: add troubleshooting steps for EADDRINUSE
refactor:Code restructuring without feature or bug changerefactor: extract reusable Button component
chore:Maintenance, dependencies, build scriptschore: upgrade Next.js to v16.3.8
test:Adding or fixing test suitestest: add unit tests for date formatter

3. Amending the Last Commit (--amend)

If you just made a commit but forgot to include a file, or made a typo in the commit message:

# 1. Stage the forgotten file:
git add forgotten-file.ts

# 2. Amend into the previous commit:
git commit --amend --no-edit

# Or edit the commit message:
git commit --amend -m "feat: correct commit message title"

On this page