Skip to content

Commit

In one line

A commit is a snapshot of your project's files at a moment in time, saved to the repository history.

In simple words

A commit is a saved checkpoint. When you make changes to your files, you stage them with git add and then save them to history with git commit -m "message". Each commit records exactly what changed, who changed it, and when.

Commits are the atoms of Git history. They stack on top of each other to form a timeline of your project. You can view the history with git log, compare any two commits with git diff, and jump back to any past commit with git checkout.

A good commit tells a story. The commit message should describe why the change was made, not just what changed — the diff already shows the what. Small, focused commits with clear messages make history easy to read and bugs easy to track down.

Example

bash
# Stage the changed files
git add index.html styles.css

# Commit with a descriptive message
git commit -m "Add hero section to homepage"

# View the commit history
git log --oneline

git add stages changes; git commit saves them to history with a message; git log shows the history.

How it works

  1. Edit files in your working directory.
  2. Stage the changes with git add — this moves them to the staging area.
  3. Commit with git commit -m "message" — this saves a snapshot to history.
  4. Each commit gets a unique hash (e.g. a1b2c3d) for identification.

Related terms

Related Resources

Related Lessons

Related Projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary