What is a Commit
A commit is the central object in Git's history. It contains a pointer to a tree (the project snapshot), zero or more parent pointers (the history), an author, a committer, a timestamp, and a message.
How it works
When you run git commit, Git:
- Creates a tree object from the current index.
- Creates a commit object with that tree, the current HEAD as parent, your author info, and the message.
- Computes the SHA-1 hash of the commit object.
- Updates the current branch ref to point to the new commit.
The first commit in a repository has no parent. A normal commit has one parent. A merge commit has two or more parents. These parent pointers form a directed acyclic graph (DAG) — the complete history of the project.
Because the commit hash includes the parent hash, changing any ancestor changes every descendant's hash. This gives Git end-to-end integrity: if the latest commit hash matches, the entire history matches.
Why it matters
Commits are immutable snapshots, not diffs. Checking out any commit gives you the complete state of the project at that point, without replaying patches. This makes checkout O(1) relative to history depth and makes operations like bisect efficient.
See How Git Objects Work for the full object model and DAG structure.