If your DVC cache is taking up too much disk space, or you want to remove cached data before starting fresh, you have a few options. The safest approach is usually to let DVC identify and remove data that is no longer needed. Deleting cache files manually can also work, but it may affect other branches, projects, or workspaces that rely on the same cache.
How Do I Clear the DVC Cache?
To remove cached data that is not needed by your current workspace, open a terminal in your DVC project and run:
dvc gc --workspace
DVC GC means “garbage collection.” The command checks which data files are referenced by the selected workspace and removes unused files from the local DVC cache. Depending on your DVC version and settings, DVC may ask you to confirm before deleting data. Review the prompt carefully before proceeding.
This command does not normally delete the data files in your working directory. It removes cache objects that DVC considers unnecessary for the selected scope. If you later need a removed file, you may be able to retrieve it from a remote storage location, provided it was pushed there.
What Is the DVC Cache?
DVC stores versions of data and model files in a cache, usually inside the project’s .dvc/cache directory. Instead of committing large datasets to Git, a project can track them with DVC while Git stores small metadata files that describe the data. The cache holds the actual file contents that DVC uses to restore or reproduce those versions.
The cache may contain data used by the current workspace, previous commits, branches, or other projects that share the same cache. That is why “clear the cache” can mean different things. You might want to remove only unneeded files, clear a shared cache completely, or clean up a remote DVC storage location. Choose the method that matches your goal.
Check the Cache Location Before Cleaning
Do not assume the cache is always located at .dvc/cache. A project can use a custom cache directory, and multiple projects may share one. To see the configured location, run this command from the project:
dvc cache dir
You can also inspect the project’s DVC configuration with:
dvc config --list
Look for a cache directory setting, such as cache.dir. If the path is on a shared drive or is used by several repositories, be especially cautious: deleting files from it may affect more than the project you currently have open.
Choose the Right DVC Garbage-Collection Scope
The scope you select determines which versions DVC protects while cleaning the cache. Keep in mind that a narrow scope can make data from older versions unavailable locally. If you work across multiple branches or need to reproduce old experiments, select a broader scope or confirm that the required data has been pushed to remote storage first.
-
Current workspace: Run
dvc gc --workspaceto preserve data referenced by the workspace you are currently using. -
All branches: Run
dvc gc --all-branchesto retain data referenced by branches in the repository. -
All tags: Run
dvc gc --all-tagsto retain data referenced by Git tags. -
All commits: Run
dvc gc --all-commitsto retain data referenced by commits in the repository.
These options protect different sets of project history. Check the options supported by your installed DVC release with dvc gc --help before running a cleanup. DVC versions can differ, and the available flags may not be identical.
For example, if you want to clean up while retaining data for every commit, use:
dvc gc --all-commits
Use this broader scope when historical data matters, but remember that it can leave more files in the cache than a workspace-only cleanup.
How to Clear the Entire Local DVC Cache
If you truly want to empty the local cache, first check its location with dvc cache dir. Then make sure no other project or workspace depends on that cache. A full manual deletion is destructive: DVC will no longer have those cached contents available locally, even if the project’s metadata still refers to them.
On macOS or Linux, if you have confirmed that the cache is project-specific and you intend to remove it, you could delete the cache directory with:
rm -rf .dvc/cache
On Windows Command Prompt, a comparable command for the default project cache is:
rmdir /s /q .dvc\cache
These commands permanently remove the selected directory and do not ask DVC to check which files are safe to delete. Verify the path before running either command, especially if your cache is configured outside the repository. Avoid deleting the whole .dvc directory: it contains project configuration and metadata, not just cached data.
After a full cache deletion, DVC may need to download data again or rebuild it through a pipeline. If a required file is unavailable in remote storage and cannot be reproduced, removing its only cached copy may make it impossible to restore.
Clear a Remote DVC Cache Separately
A local cache and a DVC remote are different storage locations. Removing unused files from your local cache does not necessarily remove anything from remote storage. Conversely, cleaning a remote does not automatically free space on your computer.
DVC supports garbage collection for remote storage in versions that provide the relevant option. Check your installed command’s help first:
dvc gc --help
If your version supports remote garbage collection, its options may include --cloud and a scope such as --all-branches or --all-commits. For example, the form may look like:
dvc gc --cloud --all-branches
Confirm the exact syntax for your DVC version and configured remote before using it. Remote garbage collection can affect data used by teammates or other projects, particularly when storage is shared. Coordinate with anyone who relies on that remote, and choose a scope that protects the versions they still need.
What to Do If You Need the Data Again
If you removed cache files but still have valid DVC metadata and the data exists in a configured remote, you can usually download the required files again. From the project, use:
dvc pull
To restore tracked outputs from data already available in the local cache, use:
dvc checkout
If an output is missing from the cache and remote storage, dvc checkout cannot recreate it by itself. You may need to run the relevant pipeline stage, for example with dvc repro, if the stage has valid dependencies and commands. A pipeline rebuild is not guaranteed to reproduce identical results if inputs, software versions, or external resources have changed.
Common DVC Cache-Cleanup Mistakes
- Deleting the cache without checking its path: A custom cache path may point to a shared location or a directory outside the repository.
- Using the current workspace as the only scope: Older branches, tags, or commits may no longer have their data cached afterward.
- Assuming Git contains the data: Git usually tracks DVC metadata, while DVC cache or remote storage holds the data itself.
- Confusing local and remote cleanup: A local cleanup and a remote cleanup are separate operations and have different effects.
-
Removing the entire
.dvcdirectory: This can delete configuration and metadata needed by the project, not just the cache. - Skipping a recovery check: Before deleting files, make sure important data can be downloaded from a remote or regenerated from a pipeline.
A Safer DVC Cache-Cleanup Checklist
Before clearing DVC cache files, follow these steps:
- Run cleanup commands from the correct DVC project.
- Use
dvc cache dirto confirm the actual cache location. - Decide whether you need to preserve the current workspace, branches, tags, or all commits.
- Check that important data is available in remote storage or can be reproduced.
- Review
dvc gc --helpfor options supported by your DVC version. - Be cautious with shared caches and shared remotes, and coordinate with other users.
Conclusion
The simplest way to clear unneeded local DVC cache files is usually dvc gc --workspace. Select a broader scope if you need to preserve data for branches, tags, or historical commits. If you intend to empty the entire cache, confirm its location and make sure no other project depends on it before deleting anything manually. For remote cleanup, check your DVC version’s supported options and protect data that teammates may still need. Taking these precautions helps reclaim storage without losing access to important datasets or model versions.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.