skip to content

In DVC, a student edited one tracked camera-trap photo in place — what does `dvc status` report, and how do you keep or discard it?

level: middleimportance: should knowfreq 9%

answer

  1. workspace no longer matches the pointer
  2. changed outs, modified
  3. find the file with granular status
  4. keep: commit; discard: forced checkout
  5. linked files need unprotect first

basics

~20 s

dvc status lists data/camera-traps.dvc under changed outs as modified. To keep the edit, run dvc commit or dvc add and commit the updated pointer to Git; to discard it, run dvc checkout --force on the photo to restore the cached version.

solid answer

~50 s

`dvc status` hashes the workspace and compares it with the pointer, reporting `data/camera-traps.dvc` with `changed outs` / `modified: data/camera-traps`; `dvc data status --granular` names the photo inside the directory. With the default copy-based link (these machines cannot reflink) the cache still holds the original, so both choices are open. To keep the edit as a new version, `dvc commit data/camera-traps.dvc` — it asks for confirmation unless you pass `-f` — or `dvc add data/camera-traps` caches the new photo, writes a new `.dir` hash into the pointer, and you commit the pointer to Git. To throw it away, `dvc checkout` the photo's path; because the edited bytes exist nowhere in the cache, it asks for `--force` before overwriting them. Had `cache.type` been `hardlink` or `symlink`, the file would have been read-only, and forcing an edit through would have altered the cached object itself.

go deeper

for a junior

Recall that dvc status compares the workspace with the pointer and reports an edited dataset as modified under changed outs.

for a middle

Explain the two ways forward, dvc commit or dvc add to keep and a forced dvc checkout to discard, and why the cache is untouched under copy links.

for a senior

Show you can judge the damage by link type, locate the file with granular status, and script commits safely around the confirmation prompt.

for a principal

Decide how a lab governs corrections to shared data: who may record a new version, how it is reviewed, and whether link types that make edits dangerous are worth their disk savings.

## How DVC notices an edit DVC never watches files. Each tracked path has a recorded hash in its pointer file (`data/camera-traps.dvc` for the lab's photo folder), and the commands that check consistency recompute the workspace's hashes and compare. To keep that affordable on 1.4 million photos, DVC stores computed hashes with each file's timestamp and inode in a small state database, and re-hashes only files whose metadata changed. `dvc status` with no arguments checks every `.dvc` file and `dvc.lock`. For the student's edit it prints: ```bash $ dvc status data/camera-traps.dvc: changed outs: modified: data/camera-traps ``` The states it can report for a tracked output are worth knowing apart: | State | Meaning | |---|---| | `modified` | The data is in the workspace but its hash differs from the pointer | | `deleted` | The pointer names data that is missing from the workspace | | `not in cache` | Workspace matches the pointer, but the cache lacks the object | | `changed checksum` | Someone edited the `.dvc` file itself by hand | Because the photos are a single directory output, `dvc status` names the directory, not the photo. `dvc data status --granular` lists file-level changes inside tracked directories, which is how you find the one edited JPEG among 1.4 million. `git status` shows nothing: Git ignores the photo directory. ## Was the cache harmed? That depends on `cache.type`: - **Default (`reflink,copy`) on a file system without reflinks** — the workspace photo is an independent copy. The edit changed only that copy, and the original bytes still sit in the cache under the old hash. Nothing is lost. - **`reflink`** — the file system copied the changed blocks on write; the cache is intact as well. - **`hardlink` or `symlink`** — DVC made the file read-only. If someone forced it writable and edited it anyway, the write went into the cached object, which now holds bytes that no longer match the hash it is filed under. That version is corrupted locally and only a copy kept elsewhere can restore it. The safe route is `dvc unprotect` before editing. ## Keeping the edit If the correction was deliberate (say, a mis-rotated image), record it as a new dataset version: 1. Run `dvc commit data/camera-traps.dvc`. It stores the changed photo in the cache and rewrites the pointer with a new `.dir` hash, `size` and `nfiles`. Because the output changed, it first asks for confirmation; `-f` / `--force` skips the prompt in scripts. `dvc add data/camera-traps` has the same effect. 2. Commit the updated pointer: `git add data/camera-traps.dvc` and `git commit`. 3. The previous version is still reachable through the old commit's pointer, as long as its objects stay in the cache. Because the cache is content-addressed, recording the new version is cheap: only the edited photo becomes a new object, plus a new `.dir` listing for the directory. The other 1,399,999 photos are already cached under their unchanged hashes and are reused as they are. ## Discarding the edit If the edit was a mistake, restore the cached version: 1. Run `dvc checkout data/camera-traps/IMG_0412.jpg` (a path inside a tracked directory is a valid target). 2. DVC will not overwrite workspace content that was never saved to the cache without confirmation, so it asks for `--force`. 3. Re-run `dvc status`; it should print `Data and pipelines are up to date.` ## Habits that prevent the problem - Agree on one workflow for corrections: `dvc unprotect` when links are in use, edit, then `dvc add`. - `dvc install` adds a `pre-commit` hook that runs `dvc status` before every `git commit`, so a forgotten edit is flagged before code ships without it. - Paths listed in `.dvcignore` are invisible to `dvc status`, so an edit there will never be reported. - Keep corrections in their own Git commits with a message naming the photos, so the dataset's history explains each new pointer hash. ## Mistakes interviewers listen for - Expecting DVC to notice and version the edit automatically. - Looking in `git status` for the changed photo. - Reading `changed checksum` as "the data changed"; it means the `.dvc` file was edited. - Assuming a forced edit through a hardlink or symlink leaves the cache intact.

  • How do you find which of 1.4 million photos changed?
    `dvc status` reports only the tracked directory as modified. `dvc data status --granular` lists file-level changes inside DVC-tracked directories, naming the edited JPEG. Some granular entries can show as `unknown` when DVC lacks the information to classify them.
  • In a nightly script, why might `dvc commit` stop instead of saving the edit?
    When an output has changed, `dvc commit` asks "Are you sure you want to commit it?" and fails without an answer. Passing `-f` / `--force` skips the prompt; `dvc add` on the target records the change without asking.

  • DVC notices the edit and versions it automatically.
  • git status shows which photo was changed.
  • changed checksum means the data file was modified.
  • dvc unprotect records the edit in the .dvc file.
  • Forcing a symlinked file writable and editing it leaves the cache intact.