Clone one commit with git clone --revision
Check out a pinned Git commit with clone --revision, and add --depth=1 when your build needs the tree without its ancestors.
A build job gets a commit ID from a release manifest. The branch has moved since the manifest was written, so cloning its current tip gives you a different tree. Clone the revision named by the manifest, then choose how much history the build needs.
Pin the checkout and set the depth
Git 2.49 added git clone --revision. It accepts the full commit object ID or a ref that resolves to a commit. Store the full ID if a later build must use the same commit even after a branch or tag moves.
Set REPO to the URL and REV to the full commit ID from the manifest. Run this in a directory without an existing pinned checkout.
git clone --depth=1 --revision="$REV" "$REPO" pinned
git -C pinned rev-parse HEAD
git -C pinned rev-list --count HEAD
git -C pinned branch -avThe first query prints the pinned ID and the count is 1. The branch listing shows one detached HEAD entry and no branches.
--revision selects the tip of the history Git requests. --depth=1 cuts that history at the target commit. Git still transfers the objects it needs to check out the files at that commit. Keep more history if the build derives its version from ancestor commits.
Inspect the history your build expects
Run the same clone in a second directory with --depth=1 removed.
git clone --revision="$REV" "$REPO" with-history
git -C with-history rev-parse HEAD
git -C with-history log --oneline HEADThe ID stays the same. If the revision has parents, the log now includes its available ancestors.
For a local repository test, use a file:// URL or pass --no-local so Git uses the transport that honors shallow cloning. A plain path can use Git's local clone optimization, which ignores --depth.
A server can reject a request for a raw object ID. If you control the repository, publish a ref for the release commit and clone the full ref name, such as refs/tags/build-42. Compare HEAD with the manifest ID before running the build.