git - "git check-ignore *"和 "git ls-files --other --ignored --exclude-standard"有什么区别?

标签 git gitignore ignore

我正在尝试检查被 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 . 更新:@LeGECcomments 中指出,shell 正在解释路径名,因此支持通配符。
  • 关于git - "git check-ignore *"和 "git ls-files --other --ignored --exclude-standard"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69084527/

    相关文章:

    linux - 在 windows 上使用 linux 服务器通过 windows 共享的 git compatibilty 设置

    git - 将提交移动到不同的分支

    git - 如何排除在执行 'git status' 命令时显示的不需要的文件夹内容

    git - 从 github 存储库中删除文件但不在本地删除文件

    java - 每次 git 推送都会删除未跟踪的文件

    node.js - 通过 npm install 在 Docker 容器中访问私有(private) git repos

    git - 从历史记录中删除单个提交

    google-cloud-functions - gcloudignore不允许使用标准通配符白名单

    android - 提交 Android Studio 时忽略文件

    version-control - 让 Emacs 忽略 *.orig 文件