Git 2 reference · Basics

git commit Command (Git)

Record the staged changes as a new commit with a message; --amend rewrites the latest commit.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git commit [-m MSG] [-a] [--amend] [--no-edit]

Parameters

ParameterDescription
-m MSG Commit message (repeat for more paragraphs).
-a Stage tracked, modified files first.
--amend Replace the last commit (only before pushing).
--no-edit Keep the message when amending.

Examples

Commit with a subject and body
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'price: 9' > pricing.md
git add pricing.md
git commit -q -m 'Add pricing page' -m 'Prices are in EUR.'
git log --format='%h %s%n  %b' -1

Output

475533d Add pricing page
  Prices are in EUR.

Run this on your computer — see “Get Started” for setup.

Amend the last commit
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo typo > notes.md; git add notes.md; git commit -q -m 'Add notes'
echo fixed > notes.md; git add notes.md
git commit -q --amend --no-edit
git log --oneline | wc -l; git show --format= HEAD:notes.md

Output

2
fixed

Run this on your computer — see “Get Started” for setup.

Was this page helpful?