What Does git commit Actually Do?

What Does git commit Actually Do?

A beginner-friendly, deep walkthrough of the single most important action in Git — what happens inside your repository the moment you save a snapshot of your work.

Imagine you’re writing a long essay in a word processor. Every few paragraphs, you save a copy with a note attached — “added introduction,” “fixed typo in conclusion,” “rewrote section 3.” If you ever mess something up, you can go back to any of those saved copies and see exactly what changed and why. That, in essence, is what committing does for your code. It is the moment your work stops being a fragile, unsaved draft and becomes a permanent, labeled, recoverable point in your project’s history. This post walks through exactly what happens when you commit, why it matters, and how to do it well — without assuming you know anything about Git going in.

1Version Control and Where Committing Fits In

Before we can understand what a commit does, we need to understand the problem it solves.

What is version control?

Version control is a system that tracks changes to files over time. Instead of having files named “essay_final.docx,” “essay_final_v2.docx,” and “essay_REALLY_final.docx” scattered across your desktop, a version control system keeps one file and remembers every state it has ever been in. You can jump back to any earlier state, compare two states side by side, or merge changes made by different people. Git is the most widely used version control system in the world today, and it is used by almost every major software company, from tiny one-person projects to organizations with tens of thousands of engineers.

Where does “commit” fit in?

Within Git, a commit is the basic unit of saved history. Every time you commit, you are telling Git: “take a snapshot of my project exactly as it looks right now, and remember it forever under this label.” Each commit becomes a permanent checkpoint that you, or anyone else working on the project, can return to at any time. Without commits, Git would have nothing to track — commits are the individual beads on the string that makes up your project’s entire history.

Simple Analogy

Think of a video game with a save system. As you play, your progress only exists in memory — if the game crashes, you lose everything since your last save. Pressing “Save Game” writes your current progress to a permanent save file with a timestamp. Committing in Git is exactly like pressing “Save Game” for your code: it takes whatever state your project is in right now and writes it permanently to your project’s history, so you can always return to that exact point later.

Term

Repository

The folder Git is tracking. It contains your files plus a hidden database of every commit ever made.

Term

Snapshot

A complete picture of what every tracked file looked like at one specific moment in time.

Term

History

The full, ordered sequence of every commit ever made in a repository, from the very first to the most recent.

Term

Commit

One saved snapshot in that history, along with a message explaining what changed and why.

2The Three Areas Every File Passes Through

To understand committing, you first have to understand that Git keeps your files in three distinct places at once.

When you’re working on a project tracked by Git, a file can exist in one of three areas: the working directory, the staging area, and the repository. Understanding the journey a file takes through these three areas is the single most important mental model for understanding what a commit actually does.

The working directory

This is simply the folder on your computer where you edit files — the one you see in your file explorer or code editor. When you open a file and type new code, you are editing it in the working directory. At this point, Git has noticed the file changed, but has done absolutely nothing to save that change permanently.

The staging area

The staging area, sometimes called the “index,” is a waiting room. It’s where you tell Git, “these specific changes, out of everything I’ve edited, are the ones I want included in my next snapshot.” This is a uniquely powerful idea in Git: you don’t have to save every single change you’ve made in one go. You can edit ten files, but choose to stage and save only three of them, leaving the other seven for a later, separate snapshot.

The repository

The repository is the permanent, historical record. Once you commit, whatever was in the staging area gets copied into the repository as a new, permanent snapshot. Unlike the working directory or staging area, changes in the repository are not casually lost — they are part of the project’s recorded history from that point forward.

flowchart LR
    A["Working Directory
(you edit files here)"] -- "select changes" --> B["Staging Area
(changes waiting to be saved)"] B -- "commit" --> C["Repository
(permanent snapshot history)"] style A fill:#fafafa,stroke:#e5e5e5 style B fill:#fef2f2,stroke:#dc2626 style C fill:#111111,stroke:#111111,color:#ffffff
FIG 1 — The journey a change takes: edit, stage, then commit
i
Why the Staging Area Exists

The staging area lets you build a clean, intentional snapshot instead of an accidental dump of every change on your disk. This means each commit can tell a focused story — “fixed the login bug” — instead of an unreadable mix of unrelated edits.

3What Actually Happens the Moment You Commit

Committing feels like a single instant action, but internally, Git performs several precise steps in sequence.

When you trigger a commit, Git doesn’t just make a vague note that “something changed.” It performs a very specific, mechanical process behind the scenes, and understanding this process demystifies a lot of what feels like Git “magic.”

1

Git reads the staging area

It looks at exactly what you’ve staged — not what’s in your working directory, and not the whole project, just the specific changes you selected.

2

Git builds a snapshot of the entire project

Using the staged changes combined with the previous commit’s snapshot, Git assembles a complete picture of what every tracked file looks like at this moment — not just a list of differences.

3

Git creates a new commit object

This object bundles together the snapshot, a reference to the previous commit (its “parent”), your name and email, a timestamp, and the message you wrote describing the change.

4

Git generates a unique fingerprint for the commit

A long string of letters and numbers is calculated from the contents of the commit. This fingerprint acts as a permanent, unmistakable identifier for this exact snapshot, forever.

5

Git moves the branch pointer forward

The branch you’re working on — usually something like “main” — is updated to point at this brand-new commit, marking it as the latest point in your project’s history.

6

The staging area is cleared

Since those changes are now safely recorded in the repository, the staging area empties out, ready for you to start staging your next set of changes.

Simple Analogy

Picture a librarian who photographs an entire library shelf every time a book is added, rather than just photographing the one new book. Each photograph is a complete, standalone record of the whole shelf at that moment, labeled with a date and a note about what changed. That’s exactly how a commit works — it represents the state of your entire project, not just the piece you edited, even though only your edited files actually took up new space.

4The Anatomy of a Commit

A commit is more than just “saved files.” It’s a small, structured record with several distinct parts.

Every commit Git creates carries a fixed set of information. Understanding these parts helps you read commit history, use tools like blame and log effectively, and understand exactly what evidence a commit leaves behind.

Part of a CommitWhat It Represents
Commit hashA unique fingerprint identifying this exact commit, calculated from its contents. No two different commits ever share the same hash.
Snapshot (tree)A complete picture of every tracked file and folder at the moment of the commit.
Parent commitA pointer back to the commit that came immediately before this one, which is how Git builds a connected chain of history.
AuthorThe name and email of the person who originally wrote the change.
CommitterThe name and email of the person who actually created the commit — usually the same as the author, but not always.
TimestampThe exact date and time the commit was created.
Commit messageA human-written explanation of what changed and, ideally, why it changed.
!
Common Misconception

Beginners sometimes think a commit only stores “the difference” between the old and new file, like a diff. In reality, Git conceptually stores a full snapshot of the entire project at each commit. Git is smart about storage internally and avoids duplicating unchanged files, but the commit itself represents a complete state, not just a set of edits.

Why the Hash Matters

Because the hash is calculated from the commit’s actual contents — including its parent, message, and snapshot — even a tiny change, like fixing a single typo in the commit message, produces a completely different hash. This makes the hash a trustworthy way to verify that a commit hasn’t been silently altered.

5How Commits Link Together Into a History

A single commit is useful, but the real power of Git comes from how commits connect to each other.

Because every commit stores a reference to its parent, Git doesn’t just hold a pile of unrelated snapshots — it holds a connected chain. Starting from the very latest commit, you can walk backward through the parent references, commit by commit, all the way back to the very first commit ever made in the project. This chain is what people mean when they talk about “commit history” or “the log.”

gitGraph
   commit id: "Initial setup"
   commit id: "Add login page"
   commit id: "Fix login bug"
   branch feature
   checkout feature
   commit id: "Add signup form"
   checkout main
   commit id: "Update README"
   merge feature id: "Merge signup feature"
        
FIG 2 — A commit history chain, including a separate branch that later merges back in

Branches are just labels on commits

A branch, such as “main,” is really just a movable label pointing at a specific commit — usually the latest one on that line of work. When you commit, Git moves that label forward to the new commit automatically. This is why creating a new branch is so cheap and fast in Git: you’re not copying the whole project, you’re just creating a new label that points at the same commit as the branch you started from.

Simple Analogy

Think of commit history like a family tree, where each commit is a person, and the “parent” link is literally like a parent-child relationship. Just as you can trace your ancestry back generation by generation, Git can trace any commit’s history back through its parents all the way to the very first commit — the “founder” of the project.

“A commit doesn’t just save your code — it saves the story of how your code came to be.”

6Why Commit Messages Matter So Much

The message attached to a commit is, arguably, just as valuable as the code change itself.

A commit without a meaningful message is like a photograph with no caption, taken by someone else, found years later — you can see what it shows, but you have no idea why it was taken or what it meant to the person who took it. In a professional codebase, developers rely heavily on commit messages to understand the reasoning behind changes, especially long after the original author has forgotten the details or moved to a different project entirely.

What makes a good commit message

A strong commit message typically has a short summary line — usually under about fifty characters — that describes what changed, written as if completing the sentence “This commit will…” For example, “fix null pointer error on empty cart” is far more useful than “fixed bug” or “updates.” If more context is needed, a longer explanation can follow, describing why the change was necessary, what alternatives were considered, or what problem it solves.

Good Message Habits

  • Describes the “what” and, when useful, the “why”
  • Uses clear, specific wording instead of vague terms
  • Stays focused on a single, coherent change
  • Is written so a future teammate understands it instantly

Bad Message Habits

  • Vague labels like “fix,” “update,” or “stuff”
  • Bundling many unrelated changes into one message
  • Referring to context only the author remembers
  • Leaving the message empty or auto-generated
i
Think of Future You

Six months from now, when something breaks and you’re scanning through history looking for the commit that introduced the problem, your own past commit messages are often the only clues you’ll have. Writing them clearly is a gift to your future self as much as to your teammates.

7Different Kinds of Commits You’ll Encounter

Not every commit looks the same. Recognizing these common patterns helps you read a project’s history fluently.

Initial Commit

The very first commit in a repository, usually setting up the basic project structure. It has no parent, making it the root of the entire history tree.

Feature Commit

A commit that adds new functionality to the project, such as a new page, button, or capability the application didn’t have before.

Bugfix Commit

A commit that corrects incorrect behavior in existing code, ideally with a message explaining what was broken and how it was fixed.

Merge Commit

A special kind of commit that has two parent commits instead of one, created automatically when two separate lines of work — such as two branches — are combined back together.

Revert Commit

A commit whose entire purpose is to undo the effects of an earlier commit, while still preserving that earlier commit visibly in the project’s history rather than erasing it.

8Common Mistakes Beginners Make with Commits

Almost everyone learning Git makes these same handful of mistakes early on. Recognizing them speeds up the learning curve considerably.

Mistake

Giant, unfocused commits

Bundling a week’s worth of unrelated changes into a single commit makes history nearly impossible to understand or safely undo later.

Mistake

Vague messages

Messages like “changes” or “wip” provide no useful information to anyone reading the history in the future, including yourself.

Mistake

Committing secrets

Accidentally including passwords, API keys, or private credentials in a commit — since history is permanent, this can be extremely hard to fully remove.

Mistake

Rarely committing

Going hours or days without committing means losing the safety net of checkpoints, and risking a much larger, riskier change if something goes wrong.

!
A Note on Secrets

Because commit history is designed to be permanent and shared, sensitive information that gets committed doesn’t just disappear when you delete the file afterward — it typically remains recoverable in earlier commits. Being careful about what you stage, every single time, is one of the most important habits a beginner can build.

9Best Practices for Committing Well

A handful of simple habits separate a messy, unreadable history from a clean, trustworthy one.

1

Keep commits small and focused

Each commit should represent one logical change, ideally something you could describe in a single, clear sentence.

2

Commit often

Frequent, small commits create more checkpoints to fall back on, and make it far easier to pinpoint exactly when a problem was introduced later.

3

Review what you’re about to save

Before committing, check exactly what’s been staged so you’re never surprised by an unintended change slipping into your snapshot.

4

Write messages for readers, not for yourself right now

Assume the person reading your message has none of the context currently in your head, and write accordingly.

5

Never commit broken or untested work to shared history

On shared branches, each commit should ideally leave the project in a working state, so teammates aren’t blocked by your in-progress work.

10Commits in the Real World

Commits aren’t just a beginner exercise — they’re the backbone of how modern software is actually built at every scale.

Large open-source projects rely almost entirely on commit history to coordinate the work of thousands of independent contributors. The Linux kernel, one of the largest and longest-running software projects in the world, has accumulated well over a million commits across its history, each one a discrete, attributable change reviewed and merged into the project. Every one of those commits carries an author, a message, and a place in the chain — exactly the same fundamental structure a beginner’s very first commit has.

1M+
Commits in the Linux kernel’s history
Millions
Of public repositories rely on commit history daily
Every second
New commits are being created across the world

Code Review

Companies use commit history as the basis of code review — reviewers read the changes and messages in a set of commits before approving them, using that same information to decide whether the change is safe to merge.

Debugging and Blame

When a bug appears, engineers commonly use tools that search commit history to find exactly which commit — and which author — introduced the problematic line of code, dramatically speeding up debugging.

Auditing and Compliance

In regulated industries, permanent, attributable commit history serves as an audit trail proving who changed what, and when, which can be essential for compliance and security reviews.

11Frequently Asked Questions

Q1Does committing save my work to the internet or a remote server?

No. Committing only saves a snapshot inside your local repository, on your own computer. Sharing that history with a remote server, like one hosted online, is a separate, later step.

Q2Can I undo a commit after I’ve made it?

Yes. Git provides several ways to undo or reverse a commit’s effects, ranging from quietly rewriting recent history to creating a new commit that explicitly cancels out an earlier one, preserving the full record.

Q3What happens if I commit without staging any changes first?

Git will refuse to create a commit if nothing has been staged, since there would be no new snapshot content to save. You must stage at least one change before committing.

Q4Is a commit the same thing as saving a file?

No. Saving a file only updates it on your disk in the working directory. Committing is a separate, deliberate action that permanently records a snapshot of your staged changes into the project’s history.

Q5Can two different commits ever have the same hash?

In practical terms, no. The hash is calculated from the commit’s exact contents, and the chance of two different commits producing the same hash is astronomically small — small enough to be treated as effectively impossible.

Q6Why does a merge commit have two parents instead of one?

A merge commit represents the point where two separate lines of history come together. It needs a reference to both parent lines so Git can accurately reconstruct how the two branches’ changes were combined.

Q7Do I need to commit every single time I save a file?

No. You can save a file many times while working, and only commit once you’ve reached a meaningful, coherent checkpoint worth recording permanently in history.

12Summary and Key Takeaways

Committing is the single action that transforms your in-progress edits into a permanent, labeled, recoverable part of your project’s history. It moves whatever you’ve deliberately staged from the temporary working directory into a durable snapshot inside the repository, complete with a unique fingerprint, a link back to the commit before it, and a message explaining what changed and why. Understood this way, a commit isn’t just a technical checkpoint — it’s a small act of documentation, one that, repeated thousands of times across a project’s life, becomes the complete, trustworthy story of how that project came to be.

Key Takeaways

  • A commit is a permanent snapshot — it captures the full state of your staged files at one moment in time, not just a list of edits.
  • Files pass through three areas — the working directory, the staging area, and finally the repository, where commits live.
  • Every commit links to its parent — this chain of connections is what forms a project’s entire commit history.
  • Each commit has a unique hash — calculated from its contents, making it a reliable, tamper-evident identifier.
  • Commit messages are documentation — clear messages turn history into a readable story instead of a meaningless list.
  • Small, focused commits are better — they’re easier to review, understand, and safely undo if something goes wrong.
  • Commit history powers real engineering workflows — from code review to debugging to compliance auditing, at every scale of software project.