在 GitHub 上编辑

check-ignore

检查给定的文件或目录是否因 .dvcignore 中的模式而被 DVC 排除。

概要

usage: dvc check-ignore [-h] [-q | -v] [-d] [-a] [-n] [--stdin]
                        targets [targets ...]

positional arguments:
  targets        File or directory paths to check

描述

此辅助命令会根据 .dvcignore 文件(如果存在)检查给定的 targets 是否被 DVC 忽略。确实被忽略的目标路径将被打印出来。

选项

  • -d, --details - 显示每个目标路径所匹配的排除模式。输出格式为:<path/to/.dvcignore>:<line_num>:<pattern> <target_path>

  • -a, --all - 在 --details 列表中列出与每个目标路径匹配的所有模式。若未使用 --details,此选项无效。

  • -n, --non-matching - 在 --details 列表中包含不匹配任何模式的目标路径。每行中的所有字段(除了 <target_path>)都将为空。若未使用 --details,此选项无效。

  • --stdin - 从标准输入读取目标路径,而不是使用 targets 参数。适用于交互式调试和 POSIX 管道。

  • -h, --help - 打印使用说明/帮助信息,然后退出。

  • -q, --quiet - 不向标准输出写入任何内容。如果没有问题则以 0 退出,否则以 1 退出。

  • -v, --verbose - 显示详细的跟踪信息。

示例

首先,我们创建一个包含一些模式的 .dvcignore 文件,并准备一些文件用于测试:

$ echo "file*\n\!file2" >> .dvcignore
$ cat .dvcignore
file*
!file2

$ touch file1 file2 other
$ ls
file1  file2 other

然后,使用 dvc check-ignore 查看在当前 .dvcignore 文件下哪些文件会被排除:

$ dvc check-ignore file1
file1

$ dvc check-ignore file1 file2
file1
file2

$ dvc check-ignore other
  # There's no command output, meaning `other` is not excluded.

$ dvc check-ignore file*
file1
file2

使用 --details (-d) 可获得所有匹配项的详细报告:

$ dvc check-ignore -d file1 file2
.dvcignore:1:file*	file1
.dvcignore:2:!file2	file2

$ dvc check-ignore -d file*
.dvcignore:1:file*	file1
.dvcignore:2:!file2	file2

默认情况下,仅显示最后一个匹配的模式。若要查看所有匹配的模式,请使用 --all (-a)。

$ dvc check-ignore -d -a file2
.dvcignore:1:file*	file2
.dvcignore:2:!file2	file2

使用 --non-matching (-n) 选项时,不匹配的 targets 也会包含在详细列表中:

$ dvc check-ignore -d -n other
::	other

示例:以交互方式或编程方式检查路径

--stdin 选项提供了一种交互式调试 .dvcignore 模式的途径:

$ dvc check-ignore --stdin
> file1
file1
> other
> file2
file2

也可用于 POSIX 管道中:

cat file_list | dvc check-ignore --stdin
内容

🐛 发现问题?告诉我们!或者修复它:

在 GitHub 上编辑

有疑问?加入我们的聊天,我们会为您提供帮助:

Discord 聊天