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
# 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 --onelinegit add stages changes; git commit saves them to history with a message; git log shows the history.
How it works
- Edit files in your working directory.
- Stage the changes with
git add— this moves them to the staging area. - Commit with
git commit -m "message"— this saves a snapshot to history. - Each commit gets a unique hash (e.g.
a1b2c3d) for identification.
Related terms
Related Resources
Related Lessons
- Git Commit
How commits work
- Git Add
Staging changes before a commit
Related Practice
Related Projects
- Commit History Exercise
Practice reading and writing commit history
Learn the fundamentals
Deepen your understanding with structured lessons on this topic.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.