.gitignore异常不适用于一个目录



根目录中有一个.gitignore文件

# Ignore everything in this directory
*
# Except this file
!.gitignore
!portal
!app.js
!node_modules
!README.md

portal外,所有异常都在工作。我后来将portal添加到该文件中(它从一开始就不存在(。但是git add .没有添加该文件夹及其内容。问题出在哪里?

Git忽略模式默认情况下是递归的,因此*不仅匹配根目录中的文件,还匹配子目录中的其他文件。若要使规则仅适用于当前目录,您需要预先设置/

# Ignore everything in this directory
/*
# Except this file
!/.gitignore
!/portal
!/app.js
!/node_modules
!/README.md

提示:git check-ignore是您在使用.gitignore规则时手头上的一个方便工具。它可以告诉您要排除的文件,以及使用-v选项排除规则的来源。

相关内容