在 GitHub 上编辑
如何更新已跟踪的数据
更新已跟踪的文件或目录可能意味着修改部分数据内容,或完全替换它们(使用相同的文件名)。
另请参阅
dvc move
。
当 cache.type
配置选项设置为 symlink
或 hardlink
(非默认值,请参阅 dvc config cache
了解更多信息)时,必须谨慎更新已跟踪的文件,以避免数据损坏。这是由于 DVC 在 缓存 和 工作区 之间链接数据文件的方式所致(详见 大型数据集优化)。
如果你使用 dvc.yaml
文件和 dvc repro
,则无需手动管理阶段的输出。DVC 会在重新生成之前自动将其删除。
否则(数据是通过 dvc add
跟踪的),请使用以下方法之一在更新前将数据从缓存中“解除链接”。我们将以一个名为 train.tsv
的文件为例进行操作:
修改内容
使用 dvc unprotect
解除文件链接。这将使 train.tsv
可安全编辑:
$ dvc unprotect train.tsv
然后编辑文件内容,例如使用:
$ echo "new data item" >> train.tsv
使用 DVC 将文件的新版本重新添加进来:
$ dvc add train.tsv
$ dvc push # If you have remote storage.
$ git add train.tsv.dvc
$ git commit -m "modify train data"
$ git push # If you have an upstream repo.
替换文件
如果你想完全替换该文件,可以执行以下步骤。
首先,对 .dvc
文件使用 dvc remove
来停止跟踪该文件。这将从工作区中删除 train.tsv
(并从缓存中解除链接):
$ dvc remove train.tsv.dvc
接下来,用新内容替换该文件:
$ echo new > train.tsv
然后重新开始跟踪它:
$ dvc add train.tsv
$ git add train.tsv.dvc .gitignore
$ git commit -m "new train data"
# If you have remote storage and/or an upstream repo:
$ dvc push
$ git push