git Gitignore 以句点开头的所有文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36918540/
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-09 04:07:48  来源:igfitidea点击:

Gitignore all folders beginning with a period

gitgitignoreglob

提问by cjm2671

I want to use a .gitignorefile to ignore all folders beginning with a period (hidden folders of linux).

我想使用一个.gitignore文件来忽略所有以句点开头的文件夹(linux 的隐藏文件夹)。

I can't figure out the syntax, though I'm sure it's simple.

我无法弄清楚语法,尽管我确信它很简单。

How's it done?

它是怎么做的?

回答by CodeWizard

Use one of these patterns:

使用以下模式之一:

# ignore all . files but include . folders
.*
!.*/


# ignore all . files and . folders
.*

# Dont ignore .gitignore (this file)
# This is just for verbosity, you can leave it out if
# .gitignore is already tracked or if you use -f to
# force-add it if you just created it
!/.gitignore


# ignore all . folders but include . files
.*/


What is this pattern?

What is this pattern?

.*- This patter tells git to ignore all the files which starts with .

.*- 这个模式告诉 git 忽略所有以 .

!- This tells git not to ignore the pattern. In your case /.gitignore

!- 这告诉 git 不要忽略模式。在你的情况下/.gitignore

A demo can be found in this answer:
Git: how to ignore hidden files / dot files / files with empty file names via .gitignore?

在这个答案中可以找到一个演示:
Git: how to ignore hidden files/dot files/files with empty file names via .gitignore?

回答by Vampire

.*/will match everything that starts with a dot and is a folder

.*/将匹配以点开头并且是文件夹的所有内容

With the following command you can test it: mkdir test && cd test && git init && mkdir -p .foo .foo/.bar foo/.bar && touch .foo/dummy .foo/.bar/dummy foo/.bar/dummy && git add . && git status && echo '.*/'>.gitignore && git reset && git add . && git status

您可以使用以下命令对其进行测试: mkdir test && cd test && git init && mkdir -p .foo .foo/.bar foo/.bar && touch .foo/dummy .foo/.bar/dummy foo/.bar/dummy && git add . && git status && echo '.*/'>.gitignore && git reset && git add . && git status

回答by eddiemoya

You should be able to use the double asterisk wildcard, which represents directories at any depth.

您应该能够使用双星号通配符,它​​代表任何深度的目录。

.**/