Skip to content

Commit

A commit is an immutable snapshot of a repository at a point in time, with a unique hash, a message, an author and a parent commit; it is the unit of history in Git and other distributed version control systems.

Definition

What it is

A commit is not a diff. It is a snapshot: the complete state of every tracked file at that moment. The diff is computed on demand, by comparing the commit to its parent. That distinction matters: a commit can be checked out, signed, referenced by hash, and shared with a remote, all without reference to how it was built.

Each commit has:

  • A hash (SHA-1 for older repos, SHA-256 for newer ones) that uniquely identifies it.
  • A parent commit (or two, for a merge, or zero, for the first commit).
  • A tree object pointing to the directory structure at that moment.
  • An author (name, email, timestamp) and a committer (same shape, sometimes different).
  • A message that explains why the change was made.

Why it matters

The hash is a promise of immutability. If someone gives you a1b2c3d, you can be sure that the content behind it has not changed — because if it had, the hash would be different. That single property enables git bisect (binary search for the commit that introduced a bug), git blame (who wrote this line), git log -S (when was this string introduced), and every reproducibility guarantee the ecosystem relies on.

The commit object

graph TD
  C[Commit a1b2c3d] --> T[Tree]
  C --> P[Parent commit]
  C --> A[Author + committer]
  T --> F1[blob: file1.php]
  T --> F2[blob: file2.php]
  T --> F3[blob: file3.php]
  style C fill:#E8F5E9
  style P fill:#FFF3E0

Good commit vs bad commit

Aspect

Good commit

Bad commit

Scope

One change

Three unrelated changes

Message

Explains why

Explains what (redundant with the diff)

Message length

50 char subject, wrapped body

"fix stuff"

Revertability

Can be reverted alone

Requires a manual surgical revert

Reviewability

200 lines

5,000 lines

Timeline

  1. 2005-04-03 — Linus Torvalds starts Git after BitKeeper's license change.

  2. 2005-04-07 — First self-hosting: Git commits its own repository.

  3. 2005-04-18 — The "commit" concept is stable: snapshot, hash, parent.

  4. 2005-07-11 — Git 1.0 rc1 ships.

  5. 2008-02 — GitHub launches, making commits a social artifact.

  6. 2020-02 — Git 2.25 ships SHA-256 commit hashing as experimental.

Writing a commit message

A commit message that survives time

  1. Subject: 50 chars, imperative

    "Add retry logic to Stripe webhook" — not "Added" nor "Adding".

  2. Blank line, then body

    The body explains why: the motivation, the previous behaviour, the new behaviour, edge cases.

  3. Wrap at 72 chars

    Email-era convention that still aids git log readability.

  4. Reference issues and PRs

    "Fixes #42" auto-closes the issue when merged.

  5. Sign when required

    git commit -S (GPG) or -s (Developer Certificate of Origin). Do not skip unless the project allows it.

Common failures

Origin

The word comes from Latin: com- (together) + mittere (to send, to let go). In English, "to commit" means "to entrust" or "to bind oneself". Version control adopted it in the 1980s (via CVS and later Subversion) to name the act of committing one's changes to the shared repository — literally entrusting them to the team. Git in 2005 kept the verb and the noun.

A commit is a snapshot of your project at a specific point in time. Each commit contains a pointer to the snapshot, information about who made the changes and when, and a message that explains why the changes were made.

— Pro Git (Chacon & Straub), 2nd edition, 2014
1980s · commit como verbo en CVS
2005 · Git 0.99 nace con commits snapshot
2020 · SHA-256 commits (experimental) en Git 2.25
50 · caracteres recomendados para el subject
72 · caracteres recomendados por línea de body

Evidence

FAQ

How many changes per commit?

One conceptual change. If the message has "and" twice, split it.

Amend vs new commit?

Amend only before push. After push, amend rewrites history that others may have pulled.

Commit vs push?

Commit is local. Push sends commits to a remote. You can commit fifty times without pushing once.

Do I need a GPG signature?

Only if the project requires it. Git commits work unsigned by default.

Connections

Etymology

Origin: borrowed

  • com (prefix): Latin, "together"
  • mittere (verb): Latin, "to send, to let go"

Semantic network

CommitGitversion-coBranchMergeRebaseStashHashGit

● broader ● narrower ● related

Broader

  • Git
  • version-control

Related

Used in the garden

Sources