Skip to main content

Fixed: "Can't remove the following unsaved files without confirmation" in dvc checkout

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

dvc checkout refused to put back the committed version of a model, with ERROR: Can't remove the following unsaved files without confirmation. Use --force to force. The model file in the project had changes that DVC had never saved, and replacing it would have lost them for good. dvc add keeps such changes, and dvc checkout --force throws them away.

What I Was Doing​

A machine learning project that predicts hourly bike rentals tracks its trained model, models/model.skops, with DVC (Data Version Control). In a fresh clone of the project, bike-demand-check, I downloaded the data with dvc pull and trained the model again, with the same data and the same settings, to check that training gives the same result. DVC is installed in the project, so its commands run through uv run.

Terminal
uv run train
Output
INFO bike_demand_forecast.train: Training on 7185 hours, testing on 1460 hours
INFO bike_demand_forecast.train: Saved models/model.skops and metrics.json
INFO bike_demand_forecast.train: Test MAE 32.56, RMSE 51.77, R2 0.8011
Terminal
uv run dvc status
Output
models/model.skops.dvc:
changed outs:
modified: models/model.skops

The metrics matched the committed ones, but DVC saw a different model file. Fixed: dvc status Says a Model Is "modified" After Retraining with the Same Data explains why. I wanted the committed model back, so I asked DVC to restore it from its cache:

Terminal
uv run dvc checkout models/model.skops

What I Expected​

DVC to replace models/model.skops with the committed version. The dvc checkout reference says it "restores the corresponding versions of all DVC-tracked data files and directories from the cache to the workspace."

What I Got​

Output
Building workspace index |2.00 [00:00, 462entry/s]
Comparing indexes |3.00 [00:00, 2.70kentry/s]
ERROR: Can't remove the following unsaved files without confirmation. Use `--force` to force.
/Users/you/source/bike-demand-check/models/model.skops

The terminal after uv run dvc checkout models/model.skops: two progress bars, then ERROR: Can't remove the following unsaved files without confirmation. Use --force to force, and the model's path.

DVC stopped before it changed anything, and named the file it wouldn't replace.

What I Checked​

dvc status showed the same as before, so the model was untouched:

Terminal
uv run dvc status
Output
models/model.skops.dvc:
changed outs:
modified: models/model.skops

The terminal after uv run dvc status: models/model.skops is still modified.

The message says "without confirmation", but DVC never asked for one: it stopped. The --force help says "Do not prompt when removing working directory files", and the reference says --force "does not prompt when removing workspace files". Both suggest a prompt that doesn't exist. I reported the wording to the DVC project as treeverse/dvc#11160.

The reference explains what "unsaved" means, under --force: "Changing the current set of DVC files with git checkout can result in the need for DVC to remove files that don't match those references or are missing from cache. (They are not "committed", in DVC terms.)"

Why It Happens​

To restore a file, dvc checkout deletes the version in the project folder and puts the cached version in its place. Before deleting, it checks that the version it's about to delete is in the cache too. In DVC 3.67.1, _check_can_delete in dvc/repo/checkout.py does that check, and raises this error for every file whose current contents the cache doesn't have.

The retrained model had never been saved with dvc add, so its only copy was the file in the project folder. Replacing it would have lost it for good, and DVC won't do that unless you say so.

The Fix​

First decide whether you need the file's current contents:

  • Keep them: save them with dvc add <file>, and commit the .dvc file. That makes them a new version, and dvc checkout can then switch between the versions freely.
  • Throw them away: add --force, which tells DVC to delete the unsaved version.

Here the retrained model wasn't needed: the committed one was the one to keep. So:

Terminal
uv run dvc checkout --force models/model.skops
Output
Building workspace index |2.00 [00:00, 349entry/s]
Comparing indexes |3.00 [00:00, 3.01kentry/s]
Applying changes |1.00 [00:00, 1.24kfile/s]
M models/model.skops

M means DVC modified the file: the committed model is back.

After the Fix​

Terminal
uv run dvc status
Output
Data and pipelines are up to date.
Terminal
md5 models/model.skops
Output
MD5 (models/model.skops) = 0d54c8f60b3f6c40bce5e52814297c28

The terminal after uv run dvc checkout --force models/model.skops reports M models/model.skops, dvc status says Data and pipelines are up to date, and md5 prints the committed hash 0d54c8f60b3f6c40bce5e52814297c28.

The model's MD5 hash is the one in models/model.skops.dvc again, and DVC reports no changes. On Linux, md5sum prints the same hash; in PowerShell, Get-FileHash -Algorithm MD5 prints it in capital letters.

Common Mistakes​

MistakeWhat happensDo this instead
Adding --force without checking firstThe unsaved version is deleted, with no copy anywhereRun dvc status and decide; dvc add first if you need it
Waiting for a promptThere is none: the command has already stoppedRun it again with --force, or dvc add the file

Troubleshooting​

SymptomLikely causeFix
Can't remove the following unsaved files without confirmation from dvc checkoutThe listed files have changes that aren't in the cachedvc add to keep them, or dvc checkout --force to discard them
The same error from dvc pulldvc pull runs a checkout after downloadingThe same choice; dvc pull has --force too

FAQ​

Can I get the discarded version back after --force?​

Not from DVC: it was never in the cache, so DVC has no copy. That's why the error exists.

Why didn't DVC prompt?​

In DVC 3.67.1 there is no prompt: without --force, the command stops with this error. The help text says otherwise, which treeverse/dvc#11160 reports.

Conclusion​

Can't remove the following unsaved files without confirmation meant that dvc checkout would have deleted the only copy of the retrained model. The model wasn't needed, so dvc checkout --force models/model.skops restored the committed version, with the hash from its .dvc file. To keep a changed file instead, dvc add it first.

Additional Resources​