【问题标题】:gitignore - now to ignore files but keep child directories [duplicate]gitignore - 现在忽略文件但保留子目录[重复]
【发布时间】:2014-07-22 00:00:50
【问题描述】:

我想忽略目录中的所有文件,但不忽略任何子目录及其内容。比如……

parentdir
   childdir
      filea
      fileb
   file1
   file2
   file3

所以,我想忽略 file1、file1、file3,但保留其他所有内容。我该怎么做?

【问题讨论】:

    标签: git gitignore


    【解决方案1】:

    您可以使用前导 ! 来否定模式,重新包括以前模式排除的任何名称。这应该有效:

    parentdir/*
    !parentdir/*/
    

    这表示要排除 parentdir 内的所有内容(但不排除 parentdir 本身),但不要排除任何目录 - 尾部斜杠将匹配目录但不匹配文件。

    【讨论】:

    • 谢谢...但要么它不起作用,要么我没有正确遵循您的指示。这是我的 .gitignore 文件的内容(我不知道如何格式化评论)... .tmp .idea node_modules !node_modules/.bin/
    • @mortsahl 你忽略了node_modules;你需要写 node_modules/* 来忽略它的孩子。
    • 再次感谢 - 仍然没有工作。我现在使用 code .tmp .idea node_modules/* !node_modules/.bin/ 签入新的 Bitbucket 存储库,然后克隆到新目录。 node_modules 被忽略了……但 node_modules/.bin/ 也是如此。
    • 知道了——因为它是一个隐藏目录我不想被忽略我不得不`node_modules/.*/`
    猜你喜欢
    • 2016-04-05
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 2021-06-07
    • 2020-02-17
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多