Synopsis
git unpack-objects [-r] [-q] < <pack-file>
Description
The git unpack-objects command reads a packfile from stdin and writes its contents as individual loose objects into the object database. This is the inverse of git pack-objects.
In day-to-day use, git unpack-objects integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git unpack-objects --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git unpack-objects interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git unpack-objects's side effects helps avoid all three.
When to Use
Most developers never need this. It's used for recovering from a corrupt pack (unpack what's salvageable, then re-pack), for testing, or when integrating a small bundle into a repo where the loose-object format is preferable.
Common Options
| Option | Description |
|---|---|
-n | Dry-run: show what would be unpacked. |
-q | Quiet, no progress. |
-r | Recover what's possible from a damaged pack. |
--strict | Refuse to write objects with broken links. |
Examples
git unpack-objects < pack-abc.pack
# Explode pack into loose objects
git unpack-objects -r < broken.pack
# Salvage what we can from a damaged pack
git unpack-objects -n < somepack.pack
# Just preview what would be unpacked
Common Mistakes
Unpacking a huge pack creates many tiny files and slows the filesystem. Almost every operational scenario prefers keeping the pack intact. Pair this with git fsck when troubleshooting corruption. git help unpack-objects opens the full manual page with comprehensive coverage of every option and edge case; it remains the authoritative reference whenever the summary on this page leaves a question unanswered. For team workflows, capturing how your project uses this command in a CONTRIBUTING document avoids repeated onboarding questions and keeps everyone aligned on conventions.
Related Commands
git pack-objects, git verify-pack, git fsck, git gc