.gitignore中的子文件夹 [英] Subfolders in .gitignore

查看:375
本文介绍了.gitignore中的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的回购中有很多子文件夹,其中有很少的 build / 目录,在提交我的代码时我想忽略它们。据我了解,有两种方法可以忽略所有的文件夹:


  • * / build / (Unix通配符)
  • build / git 忽略文件/文件夹的方式)



我发现 Git忽略子文件夹,但它有两个答案,我想知道两种方法之间的差异(无?)是。同样的规则适用于文件吗?

解决方案

build / 是正确的方式来做到这一点。它会忽略任何位于 build 目录中的文件,无论这些目录嵌套在您的repo中有多深。



* / build / 表示忽略构建在您的回购站内恰好一级的目录 。因此,例如 build foo / bar / build 中的文件不会被忽略。



如果您需要更精细的控制,您可以随时添加特定的目录进行排除,但也不能使用作为前缀。 / p>

I have many subfolders in my repo, in which there are few build/ directories I'd like to ignore when committing my code. As I understand it, there are two ways to ignore all of the folders:

  • */build/ (Unix wildcards)
  • build/ (git way of ignoring files/folders)

I've found Git ignore sub folders but it has two answers and I would like to know what the difference (none?) between the two approaches is. Does the same rule apply to files?

解决方案

build/ is the right way to do it. It will ignore any files that are inside build directories no matter how deep are these directories nested in your repo.

*/build/ means ignore build directories that are exactly one level deep inside your repo. So for instance files inside build and foo/bar/build won't be ignored.

If you need more fine grained control, you can always add specific directories to exclude but also not to exclude using ! as a prefix.

这篇关于.gitignore中的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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