首页 > 解决方案 > “git check-ignore *”和“git ls-files --other --ignored --exclude-standard”有什么区别?

问题描述

我正在尝试检查 git 忽略的文件,我发现 2 个命令显示相同的结果。

哪个是

  1. git check-ignore *

  2. git ls-files --others --ignored --exclude-standard

这似乎是不同的方法,但它会在任何情况下显示相同的结果吗?

标签: gitgitignoreignore

解决方案


虽然没有具体记录,但不同之处在于git check-ignore <pathname>它不会递归到子目录1,而git ls-files --others会。

假设您的工作目录如下所示:

.
|-- ignored-file
|-- bin
|   |-- another-ignored-file

在工作目录的根目录下,如果您运行:

git check-ignore *

你会得到公正ignored-file的。如果你运行:

git ls-files --others --ignored --exclude-standard

你会得到:

ignored-filed
bin/another-ignored-file

现在,如果您要在bin目录中运行这两个命令,您将获得相同的输出。


  1. git check-ignore接受通配符实际上有点令人惊讶,因为文档调用参数pathname而不是pathspec更新:正如@LeGEC在评论中指出的那样,shell 正在解释路径名,因此支持通配符。

推荐阅读