Prevent Draft Raster Filename Collisions
Learn how to prevent filename collisions when managing reviewed raster assets by comparing Git blob hashes instead of relying on static file paths.
Table of Contents1 sections

When your build pipeline uses repeatable filenames for raster assets, a collision occurs if a new draft overwrites an approved file that shares the same path. Relying on file existence alone can lead to inconsistent state where your metadata points to the wrong bytes. To ensure integrity, you must verify the content before committing.
Quick solution:
if [ "$(git hash-object current.jpg)" != "$(git hash-object new.jpg)" ]; then
mv new.jpg "asset-$(git hash-object new.jpg | cut -c1-7).jpg"
fi
Understanding Git Object Identity
Git stores data as content-addressed objects. As detailed in the Git Internals documentation, the object ID is a SHA-1 hash of the content itself. When you manage assets, you should treat the blob hash as the source of truth rather than the filename. If you need to interact with these objects programmatically, the GitHub Git blob REST API provides methods to retrieve specific blobs by their hash, ensuring you are always working with the exact bytes approved during review.
Handling Collision Scenarios
When a draft filename collision occurs, you must decide whether to overwrite or preserve the asset. You can Validate Raster Images in CI Beyond Metadata to ensure that the file is not only correctly named but also structurally sound. Use the following logic to manage your storage:
| Scenario | Action | Result |
|---|---|---|
| New path | Write file | New asset added to catalog |
| Same blob hash | Skip write | Existing file remains valid |
| Occupied path, different bytes | Rename to hash | Both versions preserved |
Implementation Checklist
- Calculate the SHA-1 hash of the incoming raster bytes before moving the file to the production directory.
- Compare the calculated hash against the existing file at the target path if one exists.
- If hashes differ, append the short hash to the filename to prevent overwriting the approved version.
- Update your asset catalog and all draft references within the same commit to maintain consistency.
- Run a final integrity check to confirm the committed file matches the review evidence.
You Might Also Like
View all articles
Shared Git State in Parallel Agent Worktrees
Examine shared Git state hazards when running parallel AI coding agents in worktrees, and learn how to prevent ref corruption and branch name collisions.

Deferring Publication After a Budget-Safe Draft Revision
Learn how to preserve a serverless publishing workflow draft when request limits prevent same-run publication by deferring publication.

Preventing Old Draft Starvation in Publishers
Learn how to prevent older ready drafts from being starved by newly created items in single-item batch publishing workflows using a snapshot-based priority rule.