DVC data hashes and Git
Quick answer
DVC (Data Version Control) keeps lightweight data references alongside Git-managed code while storing large data and model bytes separately. A content digest identifies a particular sequence of bytes; a filename alone does not identify a dataset revision. Examples use standard-library Python; native DVC commands are not executed. ByteMind execution is unverified.
Content identity
from hashlib import sha256a=b"x,y\n1,2\n"print(sha256(a).hexdigest()==sha256(a+b"\n").hexdigest())Expected output (locally tested): False. Even an extra newline changes byte identity.
How it works
In an initialized Git and DVC repository, dvc add data.csv tracks a file by writing metadata to data.csv.dvc and caching its bytes. Git tracks the pointer and relevant ignore rules, not the large data itself. Commit reviewed pointers, pipeline definitions and code together. DVC cache layouts and hash algorithms are version-dependent; this chapter uses SHA-256 in a separate teaching implementation, not a recreation of DVC cache format. A Git commit and a matching DVC object are both needed to reconstruct a historical workspace. Changing a newline changes a file digest even if parsed values remain the same. Hashes detect byte changes but do not establish consent, authenticity, or licensing. Never track sensitive input just because it will not appear in Git; cache and remote copies still contain it. Inspect git status and the staged diff before committing.
Deduplicate immutable objects
from hashlib import sha256cache={}for b in [b"alpha",b"beta",b"alpha"]: cache[sha256(b).hexdigest()]=bprint(len(cache))Expected output (locally tested): 2. Identical bytes use a shared key in this simplified cache.
Common mistakes
Confusing a pointer with the dataset leads to missing data on another machine. Storing a hash is not anonymization; do not version secrets or personal records in this lab.
Practice and next steps
Create two tiny CSV byte strings that differ only in row order and compare their digests. Explain what a Git revision alone cannot recover.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
DVC data hashes and Git — knowledge check
Apply dvc data hashes and git to small examples and debugging scenarios.
What does a DVC pointer represent?
What changes a byte digest?
What should Git track?
Does hashing anonymize a dataset?
What is the teaching cache format?