Git:如何通过 .gitignore 忽略隐藏文件/点文件/文件名为空的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11543789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:09:41  来源:igfitidea点击:

Git: how to ignore hidden files / dot files / files with empty file names via .gitignore?

gitgitignore

提问by BerndBrot

These files should all be ignored:

这些文件都应该被忽略:

.weirdBackupFileType
.travis.yml

The following files should not be ignored:

以下文件不应被忽略:

_.weirdBackupFileType
Z.travis.yml

回答by dulvac

If you want to ignore all dotfiles, add this in your .gitignore file (If it doesn't exist, add it)

如果你想忽略所有的点文件,在你的 .gitignore 文件中添加它(如果它不存在,添加它)

.*
!.gitignore

回答by CodeWizard

Your answer is very simple:

你的回答很简单:

This is the content of your .gitignorefile:

这是您.gitignore文件的内容:

# ignore those files 
.weirdBackupFileType
.travis.yml

#DONOT ignore those files (this is what the ! is for - un ignore files)
!_.weirdBackupFileType
!Z.travis.yml

And that's it.

就是这样。

In the image you can see that i have created the file and after adding it to the .gitignorethey are not in the status any more.

在图像中,您可以看到我已经创建了该文件,并且在将其添加到该文件后,.gitignore它们不再处于该状态。

enter image description here

在此处输入图片说明