如何将没有点(其所有扩展名文件)的文件添加到gitignore文件? [英] How do I add files without dots in them (all extension-less files) to the gitignore file?

查看:99
本文介绍了如何将没有点(其所有扩展名文件)的文件添加到gitignore文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像标题所说,是否可以将没有点的文件添加到gitignore文件中?



我想这可以解决所有这些麻烦您可以尝试类似以下的组合:



<$>



$ b

  * 
!/ ** /
!*。*

gitignore 排除规则(a 否定模式)应忽略除扩展名外的所有文件。



正如下方 疯狂物理学家,规则是:

如果排除该文件的父目录,则无法重新包含文件。 *

(<$ c

这就是为什么:除非在git 2.?+中满足某些条件, > / ** / 是很重要的(如果我们想要白名单文件,则递归地列出父文件夹)。



我提到过类似案例中的相同规则,例如:






由于JakubNarębski comments ,你可能不想忽略所有的扩展名文件。



我的建议:




  • 首先添加无扩展文件

  • 然后编辑您的 .gitignore ,如上所示:已经版本化的文件不会被忽略(即使它们没有扩展名)。所有其他文件都将被忽略。



对于任何您希望版本扩展的文件:

  git add -f  -  myFile 



< hr>

请注意,使用git 2.9.x / 2.10(2016年中期?),如果该文件的父目录被排除,那么可能会重新包含一个文件如果路径中没有通配符,则重新包含



NguyễnTháiNgọcDuy( pclouds 正试图添加此功能:





然而,因为重新包含的规则之一是:


重新包含规则中的目录部分必须是literal(即没有通配符)


无论如何这不会有效。


Like the title says, is it possible to add "files without dots in them" to the gitignore file?

I imagine this would take care of all those bothersome extensionless files.

解决方案

You can try a combination similar to:

*
!/**/
!*.*

That gitignore exclusion rule (a negated pattern) should ignore all files, except the ones with an extension.

As mentioned below by Mad Physicist, the rule is:

It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.?+, see below)

That is why !/**/ is important (white-listing the parent folders recursively) if we want to white-list files.

I mentioned that same rule in similar cases like:


As Jakub Narębski comments, you might not want to ignore all extensionless files.

My advice:

  • add first the extensionless file that matters
  • then edit your .gitignore as shown above: the already versioned files won't be ignored (even if they don't have an extension). All the others will be ignored.

For any future extensionless files that you would want to version:

git add -f -- myFile


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

However, since one of the rules to re-inclusion was:

The directory part in the re-include rules must be literal (i.e. no wildcards)

This wouldn't have worked here anyway.

这篇关于如何将没有点(其所有扩展名文件)的文件添加到gitignore文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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