LinuxCommandLibrary

git-unpack-file

Extract object from a Git packfile

TLDR

Create a file holding the contents of the blob specified by its ID then print the name of the temporary file

$ git unpack-file [blob_id]
copy

SYNOPSIS

git unpack-file [--quiet] [--refresh] [--index-info] [--strict] <object> [<object> ...]

PARAMETERS

<object>
    SHA-1 object ID(s) to unpack (blobs, trees, or commits)

--quiet
    Do not complain if <object> or its chunks are missing

--refresh
    Use current file's mode and mtime instead of object's

--index-info
    Write index-format info to stdout, not filesystem

--strict
    Fail if blob matches up-to-date file stat

DESCRIPTION

git-unpack-file is a low-level plumbing command in Git used to read a Git object by its SHA-1 identifier and extract its contents into a temporary file in the current working directory. The temporary file is named using the full 40-character hexadecimal object ID.

It handles three object types: blobs (file contents written raw), trees, and commits (textual representations dumped to file). This command is invoked internally by higher-level tools like git-checkout-index and scripts needing object inspection without full checkout.

Options allow customizing behavior: silencing errors for missing objects, refreshing file metadata from the filesystem, outputting index-compatible info to stdout instead of files, or enforcing strict up-to-date checks for blobs.

Designed for repository internals, it supports both loose and packed objects, inflating compressed data as needed. Use cautiously outside scripts, as it interacts directly with object storage.

CAVEATS

Creates files named by full object hash (40 hex chars) in current directory, risking overwrites.
Intended for Git repositories; undefined outside.
Plumbing command: not for interactive use.

OBJECT HANDLING

Blobs: raw content. Trees/commits: human-readable text dump.
Supports multiple objects.

EXIT STATUS

0 on success, 1 on failure (missing object, errors).

HISTORY

Introduced in Git 1.5.0 (January 2007) as core plumbing for object extraction. Maintained across versions for script and internal use.

SEE ALSO

Copied to clipboard