Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

What a Git Commit Stores—and When Git Can Delete It

A Git commit points to a snapshot tree, not a saved diff. Learn what happens to files and commits after deletion, reset, amend, rebase, and garbage collection.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Git commit stores a pointer to a snapshot of tracked files, along with parent commit references and metadata; it does not store a patch. Git objects are immutable after creation, but that does not mean they stay forever: if no ref or reflog protects an object, Git may eventually prune it. “Git never deletes anything” is a shorthand for immutability, not a retention guarantee.

What does a Git commit actually store?

A commit object points to a root tree that describes the tracked project state. It also records its parent commit or commits and metadata. The tree contains directory entries with names, modes, object types and object IDs. An entry can point to a blob for a file or symbolic link, another tree for a directory, or a commit object for a submodule.

As an Amazon Associate I earn from qualifying purchases.

A blob holds file contents. If a commit changes only two files, Git can create new blobs for those files while reusing the existing object IDs for unchanged files. The snapshot model therefore does not require a full duplicate copy of every file for every commit. The snapshot covers tracked state, not untracked files sitting in a working directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The object ID identifies an object’s contents under the repository’s Git object format. Git’s current core data model manual states: “Git objects never change after they’re created.” That describes whether an object is modified in place; it does not promise permanent retention.

Does Git store a snapshot or a diff?

Git stores the commit’s tree snapshot, not the diff as the commit’s payload. When Git displays what changed, it compares the commit’s tree with a parent tree. As the Git data model manual puts it: “Git does not store the diff for a commit: when you ask Git to show the commit with git-show[1], it calculates the diff from its parent on the fly.”

This is why a displayed patch is a view of the difference between two snapshots rather than a stored ingredient of the commit. A merge commit can have more than one parent, so the comparison shown can depend on which parent or diff view is used.

What happens when you delete a file?

When a file deletion is committed, the new tree simply has no entry for that path. The earlier commit still points to its earlier tree, which can still point to the blob containing the file’s contents. Deleting a file from the current version therefore does not remove it from earlier retained history.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Deleted in the latest commit” and “removed from every retained copy” are different outcomes. If sensitive content was committed, a later deletion alone does not erase it from prior commits. Rewriting history may be needed to remove it from the history you control, and collaborators may need to update their clones. Local Git’s object model does not establish what a hosting provider or its backups retain.

Do reset, amend, and rebase delete old commits?

These operations can change which commits are named by current branch tips, but they do not edit old commit objects in place. git commit --amend and rebase create replacement history. Reset or another ref move can leave earlier commits unreachable from the branch that used to point to them.

Unreachable means an object is no longer reachable from the relevant refs; it does not necessarily mean it has already been erased. Another branch, tag, remote-tracking ref, other name under refs/*, or reflog entry may still provide a path to it. The git-reflog manual describes reflogs as records of updates to references.

Recovery after history changes may be possible through a reflog or another ref, but it is not guaranteed. Reflogs expire, repository settings differ, and maintenance may already have removed unprotected objects. The Git glossary defines reachability-related terms used to describe this object graph.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When can Git garbage collection prune objects?

Git maintenance can remove objects that are no longer protected, but git gc is not a deterministic command that immediately deletes everything unreachable. The git-gc manual says: “git gc tries very hard not to delete objects that are referenced anywhere in your repository.” It also documents cleanup of unreachable objects.

The online manual documents defaults equivalent to pruning loose objects older than two weeks, and expiration defaults of 30 days for unreachable reflog entries and 90 days for ordinary reflog entries. These are configurable defaults, not a promise that a particular commit will remain recoverable for those exact periods. Reachability, object age and storage form, configured expiration rules, and repository activity can all matter. Check the installed Git version and local configuration for repository-specific behavior.

Packing stores objects together to reduce space and improve performance; it does not rewrite the logical objects or their history. Unreachable packed objects may remain unless repacking handles them, as described in the Git User Manual. The gc manual warns that pruning immediately with --prune=now increases the risk of problems if another process is writing to the repository at the same time.

How to think about whether an old commit is still recoverable

There is no single age-based answer. The relevant questions are which references still lead to the object, whether a reflog entry protects it, whether it is loose or packed, and what expiration and pruning rules are configured. A local repository and a hosted copy are separate cases: the local object lifecycle cannot tell you a host’s backup or erasure policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.