search

Home  >  Q&A  >  body text

gitignore 添加空目录

想忽略一个目录下的所有文件(包括文件夹),但要保留这个文件夹,以便github上能体现该项目目录结构的完整性.

请问这种gitignore的规则应该怎么写?

过去多啦不再A梦过去多啦不再A梦2796 days ago892

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-04-27 09:04:30

    Git will ignore empty directories. The currently more mainstream approach, in addition to the one mentioned by @Millson, there is another approach that I personally find more convenient, which is to create a new one in the directory .gitkeep 文件(文件名其实随意,不过常见的是 .gitkeep.keep)

    reply
    0
  • 習慣沉默

    習慣沉默2017-04-27 09:04:30

    Add the .gitignore file in the empty directory, the content is

    # 忽略所有文件
    *
    # 除了这个文件
    !.gitignore
    

    Then git add empty can

    reply
    0
  • 漂亮男人

    漂亮男人2017-04-27 09:04:30

    I remember that git cannot submit an empty directory, but it may be possible to work around it, first let there be files in the folder, and then delete the files. Just to provide ideas, you can try it

    reply
    0
  • Cancelreply