Skip to content

Committing changes

This page explains how to create clean commits and write helpful messages.

When to commit

Commit when you have a small, complete change that builds/tests on its own. Prefer multiple small commits over one large commit.

Staging changes

# Review what changed
git status

git add <file>
# Or stage everything
git add .

Write a good commit message

A good commit message is a short summary (50–72 characters), written in present tense.

Common patterns

  • Add: Add login retry limit
  • Fix: Fix null check in payment flow
  • Docs: Update onboarding steps
  • Refactor: Refactor cache invalidation logic
  • Chore: Bump dependencies

Examples

Good

  • Add health check endpoint
  • Fix crash when cache is empty
  • Refactor auth token parsing
  • Update deployment guide

Avoid

  • WIP
  • Update
  • Changes
  • Fix stuff

Amending the last commit

Use this to add missed files or improve the message before pushing.

# Add missed files
git add <file>

# Amend message or content
git commit --amend

Splitting a large change

If you accidentally staged too much:

# Unstage everything
git reset

# Stage only what you want
git add -p

FAQ

Can I edit pushed commits?

Avoid rewriting history on shared branches. Instead, create a new commit to fix issues.

How to revert a commit?

Use git revert <commit-hash> to create a new commit that undoes the changes.

How to undo a commit without creating a new one?

Use git reset --soft HEAD~1 to undo the last commit but keep changes staged.

Why use present tense in commit messages?

It describes what the commit does, making it easier to understand the project history.

What if my commit message is too long?

Break it into a short summary and a detailed body separated by a blank line.

Should I include issue/ticket numbers?

Yes, if applicable, include references to related issues or tickets for context.

Why should I care about commit quality?

High-quality commits improve collaboration, make code reviews easier, and help maintain a clear project history.

I use changelogs, do commit messages still matter?

Yes, commit messages provide context for changes that changelogs may not capture. They help understand the reasoning behind changes during code reviews and debugging.