gitignore 子目录的内容

gitignore contents of subdirectories

我的目录结构如下:

a
|-- b
|   |-- qfq.txt
|   |-- ewfw.txt
|   | ...
|
|-- c
|   |-- wgfw.txt
|   |-- wjkh.txt
|   | ...
| ...

我需要 gitignore a/*/ 中的所有 txt 文件。我尝试了 /a/*/*.txt/a/**/*.txt,但它们不起作用。

请帮忙。谢谢。



更新: 已解决

/a/**/*.txt 有效。另外,我开始知道 git doesn't commit empty folders,不知道我认为哪些命令无法正常工作。

感谢@JonathonReinhar、@phd、pankaj 的快速回复。

在你的 .gitignore 中添加这个应该可以 -

$ cat .gitignore 
a/**/*.txt

检查这个,我创建了相同的目录和文件结构

$ find . -name *.txt 
./a/c/wjkh.txt
./a/c/wgfw.txt
./a/b/qfq.txt
./a/b/ewfw.txt

但我的 "git status" 很干净

$ git status
On branch master
nothing to commit, working tree clean

确保您首先将 .gitignore 提交到存储库,然后它才会开始忽略文件。

希望对您有所帮助