← Journal
Keep Large Data Files Out of Git: Running DVC

Keep Large Data Files Out of Git: Running DVC

A record of using DVC to version a data file with network access disabled. Rewriting the data changed the hash in the pointer file that Git tracks as expected.

Repository covered in this article

iterative/dvc

🦉 Data Versioning and ML Experiments

15.8k Python Apache License 2.0

Putting training data or preprocessed datasets in Git makes the repository grow. DVC brings data versioning into Git's workflow: it keeps the data files elsewhere and records lightweight pointer files in Git, with each pointer linking to a content hash. I installed DVC and tested version tracking with network access disabled.

DVC tracks data files by content hash. The Git repository stores .dvc pointer files with those hashes, while DVC keeps the data files out of the repository. The project publishes its source code under the Apache 2.0 License (*1).

1. Install DVC

FROM docker.io/library/python:3.12.13-slim
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --quiet 'dvc==3.67.1'
WORKDIR /work
podman build -t dvc-sandbox .

2. Change the data and inspect the pointer file

I initialized a Git repository and used DVC to track a small CSV file. I changed the file contents and tracked it again. I ran the commands with network access disabled.

git init -q
dvc init -q

echo "id,label
1,cat
2,dog
3,cat" > dataset.csv
dvc add dataset.csv -q
cat dataset.csv.dvc

echo "id,label
1,cat
2,dog
3,cat
4,dog
5,cat" > dataset.csv
dvc add dataset.csv -q
cat dataset.csv.dvc
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work dvc-sandbox \
  bash dvc_demo.sh

The -v option makes the specified directory readable and writable from the container. Run this command from an empty experiment directory.

The command printed the following output.

--- .dvc pointer file after first version ---
outs:
- md5: f3feb34d6eeb2c2d1ba6590431f494f6
  size: 27
  hash: md5
  path: dataset.csv

--- .dvc pointer file after modifying dataset.csv ---
outs:
- md5: 12307d62197dc4d20f2c4f3ee37f0106
  size: 39
  hash: md5
  path: dataset.csv

Changing the data file from three lines to five changed both the MD5 hash and the file size that the .dvc file records. The size changed from 27 bytes to 39 bytes. Git commits the few-line .dvc file, while the data file itself remains outside Git's version history.

Keep Large Data Files Outside Git

As data files grow, storing them in a Git repository becomes impractical. DVC leaves Git with a pointer and stores the data elsewhere. You can keep the repository small and track which data belongs to which version.

Sources

*1 DVC (GitHub), https://github.com/iterative/dvc, Apache 2.0 License