我正在尝试检查被 git 忽略的文件,我发现 2 个命令显示相同的结果。
哪个是
git check-ignore *
git ls-files --others --ignored --exclude-standard
这似乎是不同的方法,但它会在任何条件下显示相同的结果吗?
最佳答案
虽然没有具体记录,但区别在于 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
中运行这两个命令目录,您将获得相同的输出。git check-ignore
实际上有点令人惊讶完全接受通配符,因为文档调用参数路径名而不是 pathspec . 更新:如 @LeGEC在 comments 中指出,shell 正在解释路径名,因此支持通配符。 关于git - "git check-ignore *"和 "git ls-files --other --ignored --exclude-standard"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69084527/