LinuxCommandLibrary

git-get-tar-commit-id

Get commit ID of tarball

TLDR

Extract commit hash ID or quietly exit with a return code of 1

$ git < [path/to/archive.tar] get-tar-commit-id
copy

SYNOPSIS

git get-tar-commit-id

DESCRIPTION

git get-tar-commit-id is a Git plumbing command designed to read tar archives generated by git-archive and retrieve the embedded commit ID. It processes input from standard input (stdin), expecting a tarball created with --format=tar or --format=ustar. The commit ID is stored in a global extended pax header named GITARCHIVECOMMITID, which git-archive automatically includes.

This tool is essential for scenarios where tarballs are distributed without the full Git repository, such as software releases or deployments. By piping a tar archive to it, users can verify the exact commit SHA-1 used to create the archive, ensuring integrity and traceability.

For example, to check the commit of the current HEAD tarball: git archive --format=tar HEAD | git get-tar-commit-id. It outputs only the 40-character hexadecimal commit ID to stdout, making it script-friendly.

The command fails silently or with an error if the header is missing or the format is invalid, emphasizing its low-level, non-user-facing nature. It's not intended for arbitrary tar files—only those from Git.

CAVEATS

Only works with tar archives from git-archive --format=tar or --format=ustar; fails on arbitrary or compressed tars without the GITARCHIVECOMMITID pax header.
Reads exclusively from stdin; no file arguments supported.

EXAMPLE

git archive --format=tar v1.0 | git get-tar-commit-id
Outputs: abc123... (commit SHA-1)

PAX HEADER

Relies on POSIX.1-2001 extended header GITARCHIVECOMMITID for SHA-1 storage.

SEE ALSO

Copied to clipboard