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
Syntax
git commit [-m MSG] [-a] [--amend] [--no-edit]
Parameters
| Parameter | Description |
|---|---|
-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
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.
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.
Related
git add· Stage changes for the next commit: whole files, all changes, or selected hunks with -p.git log· Show commit history: one line per commit, as a graph, filtered by author, date, path or message.git reset· Move the current branch to another commit, keeping changes staged (--soft), unstaged (default) or discarding them (--hard).- Staging and Committing · tutorial