我dvc add编辑了一个我不想添加的文件。我还没有承诺。
如何撤消此操作?在 Git 中,你会做git rm --cached <filename>.
明确一点:我想让 DVC 忘记该文件,并且我希望该文件在我的工作树中保持不变。这与dvc remove所做的相反。
DVC 问题跟踪器上的一个问题表明这dvc unprotect是正确的命令。但阅读手册页表明并非如此。
这对 DVC 可行吗?
根据 DVC Discord 服务器上的 mroutis:
dvc unprotect文件; 如果您不使用symlink或不hardlink缓存,这将不是必需的,但它不会受到伤害。dvc gc或查找 MD5data.dvc并手动将其从.dvc/cache.编辑——他们的 Github 页面上现在有一个问题,可以将其添加到手册中:https ://github.com/iterative/dvc.org/issues/625
dvc remove似乎可以为未提交的文件执行您需要的操作 - 至少对于不在管道中的文件。关键(我从错误或文档中不清楚)是传递….dvc文件名,否则它会尝试从dvc.yaml.
# Precondition: DVC is configured for the repo. No dvc.yaml file (untested with it)
$ touch so-57966851.txt
$ dvc add so-57966851.txt
WARNING: 'so-57966851.txt' is empty.
100% Adding...|████████████████████████████████████████|1/1 [00:00, 49.98file/s]
To track the changes with git, run:
git add .gitignore so-57966851.txt.dvc
# Ooops! I did the wrong thing! I didn't mean to add that…
$ dvc remove so-57966851.txt.dvc
$ ll so-*.txt
-rw-r--r-- 1 ibboard users 0 Aug 23 20:27 so-57966851.txt
(使用 v2.5.4 测试)