﻿# GitHub Contents API: distinguish blob SHA from commit SHA

Use GitHub repository content identities correctly: distinguish file blobs, commit snapshots and branch references before preparing a Contents API modification.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-github-contents-blob-versus-commit-sha/
Language: en

## Identify which Git object the field describes

The [Git blobs reference](https://docs.github.com/en/rest/git/blobs) defines a blob as the object containing a file's contents. The [Git commits reference](https://docs.github.com/en/rest/git/commits) defines a commit through a tree, parent commits and associated metadata. Both APIs return a sha, but those identifiers address different object types. An editorial integration record should label the object type beside the value. Keeping an undifferentiated variable called latest_sha invites accidental use of a branch's commit identity where file contents are required.

## Resolve the file on the intended branch

The [Contents API reference](https://docs.github.com/en/rest/repos/contents) accepts a ref when reading repository content and a branch when creating or updating a file. An update requires the blob SHA of the file being replaced. A proposed client should preserve repository, path and branch together with that blob identity. Reading the default branch and then updating a different branch is not a coherent observation, even when the path exists in both and their file contents sometimes coincide.

## Treat representation encoding separately from object identity

The blob API exposes content with an explicit encoding, while the Contents mutation accepts Base64-encoded file contents. A blob SHA is not a hash of arbitrary reserialized API JSON or of the textual Base64 representation. An editorial fixture can use a small known byte sequence and verify decoding before constructing the update. Text newline transformations should be deliberate because they change the proposed file contents, not merely the surrounding request formatting.

## Read the created commit as a separate result

The Contents update response contains content information and a commit object. Preserve both when describing what a successful mutation produced. The commit identifies the new repository history point; the returned file identity supports later inspection of that path. Creating a blob through the lower-level Git API alone does not update a branch reference. A multi-file publication using trees and commits is consequently a different workflow from one Contents API file operation.

## Make conflict handling specific to the file workflow

The Contents reference warns that concurrent create/update and delete operations can conflict and should be performed serially. A proposed client must resolve a conflict against the intended file and branch rather than replacing every SHA with an arbitrary newest commit. [Contract fixtures](/journal/provider-golden-contract-fixtures/) help preserve object-type checks, while [release manifests](/journal/tokenizer-artifact-release-manifest/) explain why successfully changing one repository file does not establish a coherent model-artifact release. This guide describes the API contract and performs no repository mutation.
