更新 DVC 中的跟踪目录

Updating tracked dir in DVC

根据this tutorial,当我更新文件时,我应该首先从 DVC 控制下删除文件(即执行 dvc unprotect <myfile>.dvcdvc remove <myfile>.dvc),然后通过 [=13= 再次添加它].但是不清楚我是否应该对目录应用相同的工作流程。

我的目录在 DVC 控制下,结构如下:

data/
    1.jpg
    2.jpg

我是否应该运行 dvc unprotect data 每次更新目录内容?

更具体地说,我感兴趣的是我是否应该 运行 dvc unprotect data 在以下用例中:

仅当文件更新时 - 即使用编辑器编辑 1.jpg AND 仅当启用了 hadrlink 或符号链接缓存类型时。

请检查这个 link:

updating tracked files has to be carried out with caution to avoid data corruption when the DVC config option cache.type is set to hardlink or/and symlink

我强烈建议阅读此文档:Performance Optimization for Large Files 它解释了使用 hardlinks/symlinks 的好处。

上面的链接不再有效 -> 这里是 up-to-date link 并在此处粘贴说明:

修改内容

使用 dvc unprotect 取消链接文件。这将使 train.tsv 可以安全编辑:

dvc unprotect train.tsv

然后编辑文件的内容,例如:

echo "new data item" >> train.tsv

用 DVC 添加新版本的文件:

dvc add train.tsv
git add train.tsv.dvc
git commit -m "modify train data"

如果您有远程存储 and/or 上游存储库:

dvc push
git push

正在替换文件

如果要完全替换文件,可以按以下步骤操作。

首先,通过对 .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"

如果您有远程存储 and/or 上游存储库:

dvc push
git push