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

Gitignore all folders beginning with a period

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

虽然我确信它很简单,但我无法理解语法。

怎么做的?

使用以下模式之一:

# 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?

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

开头的文件

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

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

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

.**/

.*/ 将匹配所有以点开头的文件夹

使用以下命令可以测试它: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