How to Go Back to an Earlier Version of Your Data with dvc checkout
Every commit of a DVC project points to one version of its data, through its .dvc files. Going back takes two commands: git checkout brings back the old .dvc file, and dvc checkout brings back the data it points to. This guide does it for one file and for the whole project with DVC 3.67.1, and returns to the newest version each time.
Syntax
git checkout <commit> -- <file>.dvc
dvc checkout <file>.dvc
| Part | What it means |
|---|---|
git checkout <commit> -- <file>.dvc | Puts the .dvc file as it was in <commit> into the project folder. -- separates the commit from the file's path |
<commit> | A commit hash, or HEAD~1 for the commit before the last one |
dvc checkout <file>.dvc | Replaces the data file with the version that .dvc file points to, taken from the cache |
DVC's Get Started guide describes it as "a commonly used workflow": "use git checkout to switch to a branch or checkout a specific .dvc file revision, followed by a dvc checkout to sync data into your workspace". It adds that "DVC is technically not a version control system by itself! It manipulates .dvc files, whose contents define the data file versions."
The Example
exam-scores tracks data/scores.csv with DVC, and has two versions of it, one in each commit: the first exam scores of Ana, Ben and Cara, and a later commit that corrects Ben's score and adds Dana.
Prerequisites
- DVC, in a Git repository where
dvc inithas run. Rundvc --versionto check; this guide uses DVC 3.67.1.
Step 1: See the History and the Current Data
git log --oneline
a35f5a3 (HEAD -> main) Correct Ben and add Dana
abac74a Add the first exam scores
3c7a6cd Initialize DVC
cat data/scores.csv
student,score
Ana,71
Ben,68
Cara,88
Dana,79

The project folder holds the newest version, from a35f5a3. The goal is the version from abac74a, the commit before it.
Step 2: Get One File's Earlier Version
git checkout HEAD~1 -- data/scores.csv.dvc
dvc checkout data/scores.csv.dvc
Building workspace index |2.00 [00:00, 328entry/s]
Comparing indexes |3.00 [00:00, 3.16kentry/s]
Applying changes |1.00 [00:00, 1.42kfile/s]
M data/scores.csv
cat data/scores.csv
student,score
Ana,71
Ben,64
Cara,88

git checkout printed nothing: it replaced data/scores.csv.dvc with its version from HEAD~1. dvc checkout then replaced the data to match, and M means it modified data/scores.csv. The file has the first scores again: Ben's 64, and no Dana. DVC took that version from its cache, without downloading anything.
The commands are the same in PowerShell, which passes HEAD~1 and -- to Git unchanged (checked in PowerShell 7.6).
Step 3: See What Changed in Git
git status --short
M data/scores.csv.dvc

The old .dvc file is staged, ready to commit. From here you have two choices:
- Keep the old version as the current one: commit the
.dvcfile. The Get Started guide does it withgit commit data/data.xml.dvc -m "Revert dataset updates", adding that there is "no need to do dvc push this time since this original version of the dataset was already saved". - Return to the newest version, as the next step does.
Step 4: Return to the Newest Version
HEAD is the last commit, so the same two commands with HEAD bring the newest version back:
git checkout HEAD -- data/scores.csv.dvc
dvc checkout data/scores.csv.dvc
Building workspace index |2.00 [00:00, 453entry/s]
Comparing indexes |3.00 [00:00, 3.15kentry/s]
Applying changes |1.00 [00:00, 1.42kfile/s]
M data/scores.csv
cat data/scores.csv
student,score
Ana,71
Ben,68
Cara,88
Dana,79

Go Back with the Whole Project
To see the whole project as it was at an older commit, with its code, its .dvc files and its data, check out the commit itself:
git checkout HEAD~1
Note: switching to 'HEAD~1'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at abac74a Add the first exam scores

"Detached HEAD" means you're looking at a commit rather than a branch; How to Check Out an Earlier Commit in Git explains it. Git changed the .dvc file, but not the data, which Git doesn't track. dvc status shows the mismatch, and dvc checkout fixes it:
dvc status
data/scores.csv.dvc:
changed outs:
modified: data/scores.csv
dvc checkout
Building workspace index |2.00 [00:00, 630entry/s]
Comparing indexes |3.00 [00:00, 3.42kentry/s]
Applying changes |1.00 [00:00, 1.62kfile/s]
M data/scores.csv
cat data/scores.csv
student,score
Ana,71
Ben,64
Cara,88

Without a target, dvc checkout updates every DVC-tracked file in the project. To return, switch back to the main branch and run dvc checkout again:
git checkout main
Previous HEAD position was abac74a Add the first exam scores
Switched to branch 'main'
dvc checkout
Building workspace index |2.00 [00:00, 599entry/s]
Comparing indexes |3.00 [00:00, 3.24kentry/s]
Applying changes |1.00 [00:00, 1.31kfile/s]
M data/scores.csv
cat data/scores.csv
student,score
Ana,71
Ben,68
Cara,88
Dana,79
dvc status
Data and pipelines are up to date.

Everything is back on the newest version. The commands in this section are the same in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Running only git checkout | The .dvc file is old, but the data is still the newest version, and dvc status shows modified | Run dvc checkout after every git checkout |
Running dvc checkout over a file with unsaved changes | DVC refuses with Can't remove the following unsaved files without confirmation | dvc add the change first to keep it, or see the fix below |
| Staying in detached HEAD | New commits don't belong to any branch | git checkout main when you're done looking |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
modified: right after git checkout | The data wasn't switched yet | dvc checkout |
Can't remove the following unsaved files without confirmation | The data file has changes that aren't saved with dvc add | Fixed: "Can't remove the following unsaved files without confirmation" in dvc checkout |
You are in 'detached HEAD' state | You checked out a commit, not a branch | git checkout main to return |
FAQ
Does dvc checkout download anything?
No. It takes the version from the cache: the dvc checkout reference says it "restores the corresponding versions of all DVC-tracked data files and directories from the cache to the workspace." In a fresh clone, where the cache is empty, dvc pull downloads the data first.
Can Git run dvc checkout for me?
The reference says: "For convenience, a Git hook is available to automate running dvc checkout after git checkout." The dvc install command sets it up.
Conclusion
git checkout HEAD~1 -- data/scores.csv.dvc and dvc checkout data/scores.csv.dvc brought back one file's earlier version from the cache, and the same two commands with HEAD returned to the newest. git checkout HEAD~1 moved the whole project to the older commit, where dvc checkout matched the data to it, and git checkout main with dvc checkout brought everything back.
Additional Resources
- Get Started: Data Versioning — switching between versions and returning to an earlier one.
- dvc checkout — every option, including
--forceand targets.
