Terminal GuideTerminal Guide

git commit Command Guide

Record changes to the repository

6 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git commit -m "msg"Commit with message
git commitOpen editor for message
git commit -aStage and commit tracked

Modify

--amendModify last commit
--amend --no-editAmend without changing msg
--fixup <commit>Create fixup commit

Options

-vShow diff in editor
--allow-emptyAllow empty commit
-SGPG sign commit

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git commit command records changes to the repository. It creates a snapshot of the staged changes along with a descriptive message.

bash
# Commit with inline message
git commit -m "Add user authentication feature"

# Open editor for commit message
git commit

# Stage tracked files and commit in one step
git commit -am "Fix login bug"

Writing Good Commit Messages

Good commit messages help you and your team understand the project history:

bash
# Short, descriptive message
git commit -m "Add password reset functionality"

# Multi-line message (via editor or quotes)
git commit -m "Add password reset functionality

- Add reset email template
- Create reset token generation
- Add expiration validation"

Commit Message Best Practices

  • • Keep the first line under 50 characters
  • • Use imperative mood: "Add feature" not "Added feature"
  • • Explain what and why, not how
  • • Reference issues: "Fix login bug (#123)"

Common Options

OptionDescription
-m <message>Use the given message as commit message
-a, --allStage modified and deleted files automatically
--amendModify the most recent commit
-v, --verboseShow diff in the commit message editor
--no-verifySkip pre-commit and commit-msg hooks
--allow-emptyAllow creating a commit with no changes

Amending Commits

Use --amend to modify the most recent commit:

bash
# Change the last commit message
git commit --amend -m "New commit message"

# Add forgotten files to the last commit
git add forgotten-file.js
git commit --amend --no-edit

# Amend and edit the message in editor
git commit --amend
Warning
Only amend commits that haven't been pushed to a shared repository. Amending rewrites history and can cause problems for collaborators.

Practical Examples

bash
# Standard workflow
git add src/feature.js
git commit -m "Add new feature"

# Quick commit for all tracked changes
git commit -am "Fix typo in README"

# Commit with verbose diff display
git commit -v

# Create an empty commit (useful for CI triggers)
git commit --allow-empty -m "Trigger rebuild"

# Sign commit with GPG
git commit -S -m "Signed commit"

# Commit with co-author
git commit -m "Add feature

Co-authored-by: Name <email@example.com>"

Frequently Asked Questions

How do I change the last commit message?

Use "git commit --amend" to open an editor to modify the last commit message. If you've already pushed, you'll need to force push (be careful with shared branches).

How do I add forgotten files to the last commit?

Stage the files with "git add <file>" then run "git commit --amend --no-edit" to add them to the last commit without changing the message.

What is a good commit message format?

Use a short summary (50 chars or less), optionally followed by a blank line and a more detailed description. Start with an imperative verb like "Add", "Fix", "Update".

How do I commit only some changes from a file?

Use "git add -p <file>" to interactively stage specific hunks, then commit normally. This allows you to split changes into separate commits.

Can I undo a commit?

Yes! Use "git reset --soft HEAD~1" to undo the last commit while keeping changes staged, or "git reset HEAD~1" to unstage them. Use "git revert" for a safe undo that creates a new commit.

Summary

git commit creates permanent snapshots of your changes. Write clear, descriptive messages to maintain a useful project history.

Quick Reference

  • git commit -m "msg" - Commit with message
  • git commit -am "msg" - Stage and commit
  • git commit --amend - Modify last commit
  • git commit -v - Commit with diff view

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles