Sub topic 6
Moving between data versions
Assume you know basic Git commands, can use the command line, and understand that DVC tracks large files through small pointer files. A DVC pointer file records the content hash and metadata for a dataset or model. Git versions the pointer file, while DVC restores the matching large file.
The two-step version switch
A data version is selected by a Git commit, branch, or tag. The selected revision contains pointer files such as data/raw.csv.dvc, models/model.pkl.dvc, or output information in dvc.lock.
Changing Git revisions changes these pointer files, but it does not automatically replace the files in your working directory. Run dvc checkout after the Git operation. DVC reads the new pointer files and updates workspace files to match them.
The normal sequence is:
git checkout v1.0
dvc checkoutIf the required content is not in the local DVC cache, dvc checkout cannot restore it. Download the content from the configured remote, then retry:
git checkout v1.0
dvc pull
dvc checkoutIn many projects, dvc pull also performs the checkout needed to materialize the files. Running dvc checkout explicitly makes the two responsibilities clear: dvc pull obtains cache content, and dvc checkout updates the workspace.
Inspecting what changed
Before switching, check whether the workspace has uncommitted changes:
git status
dvc statusgit status reports changed Git files, including pointer files. dvc status compares the workspace and cache with the DVC metadata. If you have changed a tracked dataset locally, switching revisions may overwrite that workspace file. Commit the change, save it elsewhere, or restore it before switching.
After switching, inspect both Git and DVC differences:
git checkout v2.0
dvc diff v1.0 v2.0
dvc checkout
dvc statusdvc diff shows which DVC-tracked files changed between revisions. It can also report additions, deletions, and changed content hashes. The final dvc status should normally report that the workspace is up to date.
| Operation | Changes Git metadata | Changes large workspace files | Needs remote access |
|---|---|---|---|
| `git checkout v1.0` | Yes | Usually no | No |
| `dvc checkout` | No | Yes | Only if cache is missing |
| `dvc pull` | No | Yes, after downloading | Yes |
| `dvc diff v1.0 v2.0` | No | No | Usually no |
Switching pipeline outputs
For a pipeline, the versioned state may be described by dvc.yaml and dvc.lock rather than by separate .dvc files. Check out both files from the desired Git revision, fetch missing cache objects, and restore the outputs:
git checkout v1.0
dvc pull
dvc checkoutIf you want to produce a new output from the older pipeline definition, use dvc repro after checkout. dvc checkout restores recorded outputs; dvc repro runs commands to create or update outputs.
Common errors
- The pointer files show the old revision, but the data looks new. Run
dvc checkout. - DVC reports a missing cache object. Run
dvc pullwith the correct remote configured. dvc checkoutwants to overwrite local changes. Inspectdvc statusand preserve the changes before continuing.- A model does not match the dataset. Restore the complete Git revision, including
dvc.yaml,dvc.lock, parameter files, and model pointers.
Exercise
You check out tag v1.0, but data/raw.csv still contains the newer dataset. What command should you run first, and what should you do if the content is not cached locally?
Show answer
Run dvc checkout. If the required object is missing from the local cache, run dvc pull and then run dvc checkout again.