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

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

问题描述

如标题所说,是否可以在 gitignore 文件中添加没有点的文件"?

我想这会处理所有那些麻烦的无扩展文件.

解决方案

你可以尝试类似的组合:

<预><代码>*!/**/!*.*

那个 gitignore 排除规则(一个 否定模式) 应忽略所有文件,但带有扩展名的文件除外.

下文所述,Mad Physicist,规则是:

如果排除文件的父目录,则无法重新包含该文件. (*)
(*:除非在 git 2.?+ 中满足某些条件,见下文)

如果我们想将文件列入白名单,这就是为什么 !/**/ 很重要(递归地将父文件夹列入白名单).

我在类似的情况下提到了相同的规则,例如:

<小时>

作为 Jakub Narębski 评论,您可能不想忽略所有 无扩展名的文件.

我的建议:

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

对于您希望版本化的任何未来无扩展文件:

git add -f -- myFile

<小时>

请注意,对于 git 2.9.x/2.10(2016 年中期?),如果排除了该文件的父目录,则可能会重新包含该文件 如果路径中没有-included> re.

Nguyễn Thái Ngọc Duy (pclouds) 正在尝试添加此功能:

但是,由于重新包含的规则之一是:

<块引用>

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

无论如何这都行不通.

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天全站免登陆