是否有多个`.gitignore'皱眉? [英] Are multiple `.gitignore`s frowned on?

查看:344
本文介绍了是否有多个`.gitignore'皱眉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除非一个回购包含多个独立的项目,否则在回购的根目录中只有一个 .gitignore 文件比最简单的文件要简单得多。有没有一个标准的最佳做法,或者在线分析一种方法比另一种更好? 在至少两种情况下,您希望在不同(子)目录中具有多个 .gitignore 文件。




  • 不同的目录有不同类型的文件要忽略。例如,项目顶部目录中的 .gitignore 会忽略生成的程序,而 Documentation / .gitignore 会忽略生成的文档。

  • 忽略给定文件只能在给定的子目录中使用 / sub / foo $ b

    请记住 .gitignore 文件递归地应用于文件所在的(子)目录及其所有子目录,除非模式包含'/'(例如模式 name 适用于给定目录及其所有子目录中名为 name 的任何文件,而 / name 最适用于文件只在给定的目录中有这个名字)。


    Unless a repo consisted of several independent projects, it seems it would be simplest to just have one .gitignore file at the root of the repo than various ones throughout. Is there a standard best practice on this or some analysis online of when one approach is better than the other?

    解决方案

    I can think of at least two situations where you would want to have multiple .gitignore files in different (sub)directories.

    • Different directories have different types of file to ignore. For example the .gitignore in the top directory of your project ignores generated programs, while Documentation/.gitignore ignores generated documentation.

    • Ignore given files only in given (sub)directory (you can use /sub/foo in .gitignore, though).

    Please remember that patterns in .gitignore file apply recursively to the (sub)directory the file is in and all its subdirectories, unless pattern contains '/' (so e.g. pattern name applies to any file named name in given directory and all its subdirectories, while /name appliest to file with this name only in given directory).

    这篇关于是否有多个`.gitignore'皱眉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆